import { Box, Typography } from "@mui/material";
import { Grid } from "../components/grid/Grid";
import { SPACING } from "../data/spacing";
import { useLocation } from "react-router-dom";
import { ProvinceRequestsOperations } from "../features/province/components/province-requests-operations/ProvinceRequestsOperations";
import { ProvinceNewRequests } from "../features/province/components/province-new-requests/ProvinceNewRequests";
import {
  ROUTE_ADMINX_REQUESTS,
  ROUTE_ADMINX_CITY_NEW_REQUESTS,
  ROUTE_ADMINX_STATEMENTـOFـNEED_REQUESTS,
  ROUTE_ADMINX_ALLOCATION_REQUESTS,
  ROUTE_ADMINX_FREE_SALES_REQUESTS,
  ROUTE_ADMINX_AWAITING_PAYMENT_REQUESTS,
  ROUTE_ADMINX_AWAITING_INSPECTION_REQUESTS,
  ROUTE_ADMINX_AUTO_ALLOCATION_REQUESTS,
  ROUTE_ADMINX_CHAINS,
  ROUTE_ADMINX_ALLOCATED_REQUESTS,
  ROUTE_ADMINX_ISSUANCE_OF_LETTER,
  ROUTE_ADMINX_EXPORT,
  ROUTE_PROVINCE_ACTIVE_REQUESTS,
  ROUTE_PROVINCE_ALLOCATED_REQUESTS,
  ROUTE_PROVINCE_ALLOCATION_REQUESTS,
  ROUTE_PROVINCE_ARCHIVED_REQUESTS,
  ROUTE_PROVINCE_AUTO_ALLOCATION_REQUESTS,
  ROUTE_PROVINCE_AWAITING_INSPECTION_REQUESTS,
  ROUTE_PROVINCE_AWAITING_PAYMENT_REQUESTS,
  ROUTE_PROVINCE_CHAINS,
  ROUTE_PROVINCE_CITY_NEW_REQUESTS,
  ROUTE_PROVINCE_FREE_SALES_REQUESTS,
  ROUTE_PROVINCE_ISSUANCE_OF_LETTER,
  ROUTE_PROVINCE_NEW_REQUESTS,
  ROUTE_PROVINCE_REJECTED_REQUESTS,
  ROUTE_PROVINCE_REQUESTS,
  ROUTE_PROVINCE_STATEMENTـOFـNEED_REQUESTS,
  ROUTE_PROVINCEـEXPORT,
  ROUTE_PROVINCEـFREE_BUY,
  ROUTE_SUPER_ADMIN_ACTIVE_REQUESTS,
  ROUTE_SUPER_ADMIN_ALLOCATED_REQUESTS,
  ROUTE_SUPER_ADMIN_ALLOCATION_REQUESTS,
  ROUTE_SUPER_ADMIN_ARCHIVED_REQUESTS,
  ROUTE_SUPER_ADMIN_AUTO_ALLOCATION_REQUESTS,
  ROUTE_SUPER_ADMIN_AWAITING_INSPECTION_REQUESTS,
  ROUTE_SUPER_ADMIN_AWAITING_PAYMENT_REQUESTS,
  ROUTE_SUPER_ADMIN_CHAINS,
  ROUTE_SUPER_ADMIN_CITY_NEW_REQUESTS,
  ROUTE_SUPER_ADMIN_EXPORT,
  ROUTE_SUPER_ADMIN_FREE_SALES_REQUESTS,
  ROUTE_SUPER_ADMIN_ISSUANCE_OF_LETTER,
  ROUTE_SUPER_ADMIN_REJECTED_REQUESTS,
  ROUTE_SUPER_ADMIN_REQUESTS,
  ROUTE_SUPER_ADMIN_STATEMENTـOFـNEED_REQUESTS,
  ROUT_SUPER_ADMIN_FREE_BUY,
  ROUTE_ADMINX_ARCHIVED_REQUESTS,
  ROUTE_ADMINX_ACTIVE_REQUESTS,
  ROUT_ADMINX_FREE_BUY,
} from "../routes/routes";
import { ProvinceRejectedRequests } from "../features/province/components/province-rejected-requests/ProvinceRejectedRequests";
import { AvicultureArchivedRequests } from "../features/aviculture/components/aviculture-archived-requests/AvicultureArchivedRequests";
import { ProvinceCityNewRequests } from "../features/province/components/province-city-new-requests/ProvinceCityNewRequests";
import { RequestsAwaitingPayment } from "../components/requests-awaiting-payment/RequestsAwaitingPayment";
import { RequestsAwaitingInspections } from "../components/requests-awaiting-inspections/RequestsAwaitingInspections";
import { BackButton } from "../components/back-button/BackButton";
import { ProvinceNeedRequests } from "../features/province/components/province-need-requests/ProvinceNeedRequests";
import { ProvinceAllocateRequests } from "../features/province/components/province-allocate-requests/ProvinceAllocateRequests";
import { ProvinceActiveRequests } from "../features/province/components/province-active-requests/ProvinceActiveRequests";
import { ProvinceFreeSales } from "../features/province/components/province-free-sales/ProvinceFreeSales";
import { ProvinceAutoAllocation } from "../features/province/components/province-auto-allocation/ProvinceAutoAllocation";
import { ProvinceAllocatedRequests } from "../features/province/components/province-allocated-requests/ProvinceAllocatedRequests";
import { SlaughterFreeBuy } from "../features/slaughter-house/components/slaughter-free-buy/SlaughterFreeBuy";
import { ProvinceSendLetter } from "../features/province/components/province-send-letter/ProvinceSendLetter";
import { getRoleFromUrl } from "../utils/getRoleFromUrl";
import { SuperAdminRequestsOperations } from "../features/super-admin/components/super-admin-requests-operations/SuperAdminRequestsOperations";
import { ProvinceChains } from "../features/province/components/chains/ProvinceChains";
import { ProvinceExport } from "../features/province/components/province-export/ProvinceExport";

const ProvinceRequests = () => {
  const { pathname } = useLocation();

  return (
    <Box display={"flex"} justifyContent="center">
      <Grid container xs={12} lg={10}>
        {pathname === ROUTE_PROVINCE_REQUESTS ||
        pathname === ROUTE_SUPER_ADMIN_REQUESTS ||
        pathname === ROUTE_ADMINX_REQUESTS ? (
          <Grid justifyContent="start" alignItems="start" my={SPACING.MEDIUM}>
            {getRoleFromUrl() === "SuperAdmin" ||
            getRoleFromUrl() === "AdminX" ? (
              <>
                <Grid>
                  {getRoleFromUrl() === "SuperAdmin" ? (
                    <Typography textAlign={"center"} variant="h6">
                      داشبورد ادمین کل
                    </Typography>
                  ) : (
                    <Typography textAlign={"center"} variant="h6">
                      داشبورد ادمین ایکس
                    </Typography>
                  )}
                </Grid>
                <SuperAdminRequestsOperations />
              </>
            ) : (
              <>
                <Grid>
                  <Typography textAlign={"center"} variant="h6">
                    داشبورد تخصیص استان
                  </Typography>
                </Grid>
                <ProvinceRequestsOperations />
              </>
            )}
          </Grid>
        ) : (
          <BackButton />
        )}

        <Grid xs={12} container>
          {(pathname === ROUTE_PROVINCE_CITY_NEW_REQUESTS ||
            pathname === ROUTE_SUPER_ADMIN_CITY_NEW_REQUESTS ||
            pathname === ROUTE_ADMINX_CITY_NEW_REQUESTS) && (
            <ProvinceCityNewRequests />
          )}
          {(pathname === ROUTE_PROVINCE_STATEMENTـOFـNEED_REQUESTS ||
            pathname === ROUTE_SUPER_ADMIN_STATEMENTـOFـNEED_REQUESTS ||
            pathname === ROUTE_ADMINX_STATEMENTـOFـNEED_REQUESTS) && (
            <ProvinceNeedRequests />
          )}
          {pathname === ROUTE_PROVINCE_NEW_REQUESTS && <ProvinceNewRequests />}
          {(pathname === ROUTE_PROVINCE_ALLOCATION_REQUESTS ||
            pathname === ROUTE_SUPER_ADMIN_ALLOCATION_REQUESTS ||
            pathname === ROUTE_ADMINX_ALLOCATION_REQUESTS) && (
            <ProvinceAllocateRequests />
          )}
          {(pathname === ROUTE_PROVINCE_ACTIVE_REQUESTS ||
            pathname === ROUTE_SUPER_ADMIN_ACTIVE_REQUESTS ||
            pathname === ROUTE_ADMINX_ACTIVE_REQUESTS) && (
            <ProvinceActiveRequests />
          )}
          {(pathname === ROUTE_PROVINCE_FREE_SALES_REQUESTS ||
            pathname === ROUTE_SUPER_ADMIN_FREE_SALES_REQUESTS ||
            pathname === ROUTE_ADMINX_FREE_SALES_REQUESTS) && (
            <ProvinceFreeSales />
          )}
          {(pathname === ROUTE_PROVINCE_REJECTED_REQUESTS ||
            pathname === ROUTE_SUPER_ADMIN_REJECTED_REQUESTS ||
            pathname === ROUTE_PROVINCE_REJECTED_REQUESTS) && (
            <ProvinceRejectedRequests />
          )}
          {(pathname === ROUTE_PROVINCE_ARCHIVED_REQUESTS ||
            pathname === ROUTE_SUPER_ADMIN_ARCHIVED_REQUESTS ||
            pathname === ROUTE_ADMINX_ARCHIVED_REQUESTS) && (
            <AvicultureArchivedRequests />
          )}
          {(pathname === ROUTE_PROVINCE_AWAITING_PAYMENT_REQUESTS ||
            pathname === ROUTE_SUPER_ADMIN_AWAITING_PAYMENT_REQUESTS ||
            pathname === ROUTE_ADMINX_AWAITING_PAYMENT_REQUESTS) && (
            <RequestsAwaitingPayment />
          )}
          {(pathname === ROUTE_PROVINCE_AWAITING_INSPECTION_REQUESTS ||
            pathname === ROUTE_SUPER_ADMIN_AWAITING_INSPECTION_REQUESTS ||
            pathname === ROUTE_ADMINX_AWAITING_INSPECTION_REQUESTS) && (
            <RequestsAwaitingInspections />
          )}
          {(pathname === ROUTE_PROVINCE_AUTO_ALLOCATION_REQUESTS ||
            pathname === ROUTE_SUPER_ADMIN_AUTO_ALLOCATION_REQUESTS ||
            pathname === ROUTE_ADMINX_AUTO_ALLOCATION_REQUESTS) && (
            <ProvinceAutoAllocation />
          )}
          {(pathname === ROUTE_PROVINCE_CHAINS ||
            pathname === ROUTE_SUPER_ADMIN_CHAINS ||
            pathname === ROUTE_ADMINX_CHAINS) && <ProvinceChains />}

          {(pathname === ROUTE_PROVINCE_ALLOCATED_REQUESTS ||
            pathname === ROUTE_SUPER_ADMIN_ALLOCATED_REQUESTS ||
            pathname === ROUTE_ADMINX_ALLOCATED_REQUESTS) && (
            <ProvinceAllocatedRequests />
          )}
          {(pathname === ROUTE_PROVINCEـFREE_BUY ||
            pathname === ROUT_SUPER_ADMIN_FREE_BUY ||
            pathname === ROUT_ADMINX_FREE_BUY) && <SlaughterFreeBuy />}

          {(pathname === ROUTE_PROVINCE_ISSUANCE_OF_LETTER ||
            pathname === ROUTE_SUPER_ADMIN_ISSUANCE_OF_LETTER ||
            pathname === ROUTE_ADMINX_ISSUANCE_OF_LETTER) && (
            <ProvinceSendLetter />
          )}
          {(pathname === ROUTE_SUPER_ADMIN_EXPORT ||
            pathname === ROUTE_PROVINCEـEXPORT ||
            pathname === ROUTE_ADMINX_EXPORT) && <ProvinceExport />}
        </Grid>
      </Grid>
    </Box>
  );
};

export default ProvinceRequests;
