import { Card } from "@mui/material";
import { Box } from "@mui/system";
import { useLocation } from "react-router-dom";
import { Grid } from "../components/grid/Grid";
import { SPACING } from "../data/spacing";
import { BasicProfileInformation } from "../features/authentication/components/basic-profile-information/BasicProfileInformation";
import { GeneralDashboardOperations } from "../features/authentication/components/general-dashboard-operations/GeneralDashboardOperations";
import {
  ROUTE_AVICULTURE_USER_PROFILE,
  ROUTE_CITY_USER_PROFILE,
  ROUTE_GENERAL_USER_PROFILE,
  ROUTE_PROVINCE_USER_PROFILE,
  ROUTE_SLAUGHTER_USER_PROFILE,
  ROUTE_INSPECTOR_USER_PROFILE,
  ROUTE_VETFARM_USER_PROFILE,
  DRIVER_USER_PROFILE,
  ROUTE_PROVINCE_FINANCIAL_USER_PROFILE,
  ROUTE_SLAUGHTER_HOUSE_VET_USER_PROFILE,
  ROUTE_STEWARD_USER_PROFILE,
  ROUTE_CITYVET_USER_PROFILE,
  ROUTE_LIVE_STOCK_USER_PROFILE,
  ROUTE_CHAIN_COMPANY_USER_PROFILE,
} from "../routes/routes";
import useUserProfile from "../features/authentication/hooks/useUserProfile";
import { CityProfile } from "../features/city/components/city-profile/CityProfile";
import { ProvinceProfile } from "../features/province/components/province-profile/ProvinceProfile";
import { VetFarmProfile } from "../features/vet-farm/components/ver-farm-profile/VetFarmProfile";
import { AvicultureProfile } from "../features/aviculture/components/aviculture-profile/AvicultureProfile";
import { DriverProfile } from "../features/driver/components/driver-profile/DriverProfile";
import { InspectorProfile } from "../features/inspector/components/inspector-profile/InspectorProfile";
import { SlaughterProfile } from "../features/slaughter-house/components/slaughter-profile/SlaughterProfile";
import { ProvinceFinancialProfile } from "../features/province-finacial/components/province-financial-profile/ProvinceFinancialProfile";
import { SlaughterHouseVetProfile } from "../features/slaughter-house-vet/components/slaughter-house-vet-profile/SlaughterHouseVetProfile";
import { GuildProfile } from "../features/guild/components/GuildProfile";
import { CityVetProfile } from "../features/city-vet/components/CityVetProfile";
import LiveStockProfile from "../features/live-stock-support/components/live-stock-profile/LiveStockProfile";
import { ChainCompanyProfile } from "../features/chain-company/components/chain-company-profile/ChainCompanyProfile";
import { BackButton } from "../components/back-button/BackButton";
import AccessDashboardV2 from "./AcessDashboardV2";

const GeneralDashboard = () => {
  const { pathname } = useLocation();
  const [roles] = useUserProfile();

  return (
    <>
      <Box display={"flex"} justifyContent="center">
        <Grid
          container
          direction="column"
          justifyContent="center"
          xs={12}
          sm={12}
          md={10}
          lg={10}
        >
          {pathname === ROUTE_GENERAL_USER_PROFILE && (
            <Grid my={SPACING.MEDIUM}>
              <Card>
                <GeneralDashboardOperations />
              </Card>
            </Grid>
          )}
          {pathname === ROUTE_GENERAL_USER_PROFILE && (
            <Grid
              container
              justifyContent="space-between"
              gap={SPACING.SMALL}
              pb={SPACING.MEDIUM}
            >
              <Grid xs={12} mb={SPACING.MEDIUM}>
                <BasicProfileInformation />
              </Grid>
              {/* <Grid xs={12} justifyContent="space-between" gap={SPACING.SMALL}>
                <ChangeCardInfo />
              </Grid> */}
            </Grid>
          )}
          {pathname === "/" ? (
            <Grid container my={SPACING.MEDIUM} xs={12}>
              <AccessDashboardV2 />
            </Grid>
          ) : (
            <Grid xs={12}>
              {window.location.pathname !== "/dashboard/profile" && (
                <BackButton />
              )}
              <Grid xs={12} mt={2}>
                {roles.map((role, i) => {
                  switch (role) {
                    case "CityOperator":
                      return (
                        pathname === ROUTE_CITY_USER_PROFILE && (
                          <Grid
                            container
                            key={role + i}
                            justifyContent="space-between"
                            gap={SPACING.SMALL}
                          >
                            <Grid xs={12} md={12}>
                              <CityProfile />
                            </Grid>
                          </Grid>
                        )
                      );
                    case "Poultry":
                      return (
                        pathname === ROUTE_AVICULTURE_USER_PROFILE && (
                          <Grid
                            key={role + i}
                            container
                            justifyContent="space-between"
                            gap={SPACING.SMALL}
                          >
                            <Grid xs={12} md={12}>
                              <AvicultureProfile />
                            </Grid>
                          </Grid>
                        )
                      );
                    case "ProvinceOperator":
                      return (
                        pathname === ROUTE_PROVINCE_USER_PROFILE && (
                          <Grid
                            key={role + i}
                            container
                            justifyContent="space-between"
                            gap={SPACING.SMALL}
                          >
                            <Grid xs={12} md={12}>
                              <ProvinceProfile />
                            </Grid>
                          </Grid>
                        )
                      );
                    case "ProvinceFinancial":
                      return (
                        pathname === ROUTE_PROVINCE_FINANCIAL_USER_PROFILE && (
                          <Grid
                            key={role + i}
                            container
                            justifyContent="space-between"
                            gap={SPACING.SMALL}
                          >
                            <Grid xs={12} md={12}>
                              <ProvinceFinancialProfile />
                            </Grid>
                          </Grid>
                        )
                      );
                    case "ProvinceInspector":
                      return (
                        pathname === ROUTE_INSPECTOR_USER_PROFILE && (
                          <Grid
                            key={role + i}
                            container
                            justifyContent="space-between"
                            gap={SPACING.SMALL}
                          >
                            <Grid xs={12} md={12}>
                              <InspectorProfile />
                            </Grid>
                          </Grid>
                        )
                      );
                    case "KillHouse":
                      return (
                        pathname === ROUTE_SLAUGHTER_USER_PROFILE && (
                          <Grid
                            key={role + i}
                            container
                            justifyContent="space-between"
                            gap={SPACING.SMALL}
                          >
                            <Grid xs={12} md={12}>
                              <SlaughterProfile />
                            </Grid>
                          </Grid>
                        )
                      );
                    case "KillHouseVet":
                      return (
                        pathname === ROUTE_SLAUGHTER_HOUSE_VET_USER_PROFILE && (
                          <Grid
                            key={role + i}
                            container
                            justifyContent="space-between"
                            gap={SPACING.SMALL}
                          >
                            <Grid xs={12} md={12}>
                              <SlaughterHouseVetProfile />
                            </Grid>
                          </Grid>
                        )
                      );
                    case "VetFarm":
                      return (
                        pathname === ROUTE_VETFARM_USER_PROFILE && (
                          <Grid
                            key={role + i}
                            container
                            justifyContent="space-between"
                            gap={SPACING.SMALL}
                          >
                            <Grid xs={12} md={12}>
                              <VetFarmProfile />
                            </Grid>
                          </Grid>
                        )
                      );
                    case "Driver":
                      return (
                        pathname === DRIVER_USER_PROFILE && (
                          <Grid
                            key={role + i}
                            container
                            justifyContent="space-between"
                            gap={SPACING.SMALL}
                          >
                            <Grid xs={12} md={12}>
                              <DriverProfile />
                            </Grid>
                          </Grid>
                        )
                      );
                    case "Guilds":
                      return (
                        pathname === ROUTE_STEWARD_USER_PROFILE && (
                          <Grid
                            key={role + i}
                            container
                            justifyContent="space-between"
                            gap={SPACING.SMALL}
                          >
                            <Grid xs={12} md={12}>
                              <GuildProfile />
                            </Grid>
                          </Grid>
                        )
                      );
                    case "CityVet":
                      return (
                        pathname === ROUTE_CITYVET_USER_PROFILE && (
                          <Grid
                            key={role + i}
                            container
                            justifyContent="space-between"
                            gap={SPACING.SMALL}
                          >
                            <Grid xs={12} md={12}>
                              <CityVetProfile />
                            </Grid>
                          </Grid>
                        )
                      );
                    case "ChainCompany":
                      return (
                        pathname === ROUTE_CHAIN_COMPANY_USER_PROFILE && (
                          <Grid
                            key={role + i}
                            container
                            justifyContent="space-between"
                            gap={SPACING.SMALL}
                          >
                            <Grid xs={12} md={12}>
                              <ChainCompanyProfile />
                            </Grid>
                          </Grid>
                        )
                      );
                    case "LiveStockSupport":
                      return (
                        pathname === ROUTE_LIVE_STOCK_USER_PROFILE && (
                          <Grid
                            key={role + i}
                            container
                            justifyContent="space-between"
                            gap={SPACING.SMALL}
                          >
                            <Grid xs={12} md={12}>
                              <LiveStockProfile />
                            </Grid>
                          </Grid>
                        )
                      );
                    default:
                      return null;
                  }
                })}
              </Grid>
            </Grid>
          )}
        </Grid>
      </Box>
    </>
  );
};

export default GeneralDashboard;
