import { Box, Typography } from "@mui/material";
import { Grid } from "../components/grid/Grid";
import { SPACING } from "../data/spacing";
import { useLocation } from "react-router-dom";
import {
  ROUTE_SLAUGHTER_ACTIVE_REQUESTS,
  ROUTE_SLAUGHTER_ALLOCATE_CAR_REQUESTS,
  ROUTE_SLAUGHTER_ALLOCATION_REQUESTS,
  ROUTE_SLAUGHTER_ARCHIVED_REQUESTS,
  ROUTE_SLAUGHTER_ENTER_BAR_INFO,
  ROUTE_SLAUGHTER_FACTORS,
  ROUTE_SLAUGHTER_FINAL_FACTORS,
  ROUTE_SLAUGHTER_NEW_REQUESTS,
  ROUTE_SLAUGHTER_PAY_FACTORS_REQUESTS,
  ROUTE_SLAUGHTER_PENDING_REQUESTS,
  ROUTE_SLAUGHTER_REJECTED_REQUESTS,
  ROUTE_SLAUGHTER_REQUESTS,
  ROUTE_SLAUGHTER_SELL_CARCASS,
  ROUTE_SLAUGHTERـEXPORT,
  ROUTE_SLAUGHTERـFREE_BUY,
} from "../routes/routes";
import { SlaughterRequests } from "../features/slaughter-house/components/slaughter-requests/SlaughterRequests";
import { SlaughterRequestsOperations } from "../features/slaughter-house/components/slaughter-requests-operations/SlaughterRequestsOperations";
import { SlaughterActiveRequests } from "../features/slaughter-house/components/slaughter-active-requests/SlaughterActiveRequests";
import { SlaughterRejectedRequests } from "../features/slaughter-house/components/slaughter-rejected-requests/SlaughterRejectedRequests";
import { SlaughterArchivedRequests } from "../features/slaughter-house/components/slaughter-archived-requests/SlaughterArchivedRequests";
import { TourProvider } from "@reactour/tour";
import { slaughterRequestsTourSteps } from "../features/slaughter-house/components/slaughter-requests/tour";
import { SlaughterAllocatedCheckRequests } from "../features/slaughter-house/components/slaughter-allocated-check-requests/SlaughterAllocatedCheckRequests";
import { SlaughterAllocateCarToRequests } from "../features/slaughter-house/components/slaughter-allocate-car-to-requests/SlaughterAllocateCarToRequests";
import { SalughterEnterBarInfo } from "../features/slaughter-house/components/slaughter-enter-bar-info/SlaghterEnterBarInfo";
import { SlaughterPayFactorRequests } from "../features/slaughter-house/components/slaughter-pay-factor-requests/SlaughterPayFactorRequests";
import { BackButton } from "../components/back-button/BackButton";
import { SlaughterFactorsComponent } from "../features/slaughter-house/components/slaughter-factors/SlaughterFactors";
import { SlaughterFinalFactorsComponent } from "../features/slaughter-house/components/slaughter-final-factors/SlaughterFinalFactors";
import { SlaughterFreeBuy } from "../features/slaughter-house/components/slaughter-free-buy/SlaughterFreeBuy";
import { useSelector } from "react-redux";
import { SlaughterExport } from "../features/slaughter-house/components/slaughter-export/SlaughterExport";
import { ProvinceAllocatedRequests } from "../features/province/components/province-allocated-requests/ProvinceAllocatedRequests";
import { SlaughterSellCarcass } from "../features/slaughter-house/components/slaughter-sell-carcass/SlaughterSellCarcass";

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

  const { slaughterPermissionState } = useSelector(
    (item) => item.slaughterSlice
  );

  return (
    <>
      <Box display={"flex"} justifyContent="center">
        <Grid
          container
          direction="column"
          justifyContent="center"
          xs={12}
          sm={12}
          md={10}
          lg={10}
        >
          {pathname === ROUTE_SLAUGHTER_REQUESTS ? (
            <Grid justifyContent="center" my={SPACING.MEDIUM}>
              <Grid>
                <Typography variant="h6">
                  صفحه مدیریت درخواست های کشتارگاه
                </Typography>
              </Grid>
              <SlaughterRequestsOperations
                hasPermission={slaughterPermissionState}
              />
            </Grid>
          ) : (
            <BackButton />
          )}

          <Grid container justifyContent="space-between" gap={SPACING.SMALL}>
            <Grid xs={12}>
              {pathname === ROUTE_SLAUGHTER_NEW_REQUESTS && (
                <TourProvider
                  steps={slaughterRequestsTourSteps}
                  disableDotsNavigation={true}
                  showButtons={false}
                >
                  <SlaughterRequests />
                </TourProvider>
              )}
              {pathname === ROUTE_SLAUGHTER_ACTIVE_REQUESTS && (
                <SlaughterActiveRequests />
              )}
              {pathname === ROUTE_SLAUGHTER_PENDING_REQUESTS && (
                <SlaughterAllocatedCheckRequests />
              )}
              {pathname === ROUTE_SLAUGHTER_ALLOCATE_CAR_REQUESTS && (
                <SlaughterAllocateCarToRequests />
              )}
              {pathname === ROUTE_SLAUGHTER_REJECTED_REQUESTS && (
                <SlaughterRejectedRequests />
              )}{" "}
              {pathname === ROUTE_SLAUGHTER_ARCHIVED_REQUESTS && (
                <SlaughterArchivedRequests />
              )}
              {pathname === ROUTE_SLAUGHTER_ENTER_BAR_INFO && (
                <SalughterEnterBarInfo />
              )}
              {pathname === ROUTE_SLAUGHTER_SELL_CARCASS && (
                <SlaughterSellCarcass />
              )}
              {pathname === ROUTE_SLAUGHTER_PAY_FACTORS_REQUESTS && (
                <SlaughterPayFactorRequests />
              )}
              {pathname === ROUTE_SLAUGHTER_FACTORS && (
                <SlaughterFactorsComponent />
              )}
              {pathname === ROUTE_SLAUGHTER_FINAL_FACTORS && (
                <SlaughterFinalFactorsComponent />
              )}
              {pathname === ROUTE_SLAUGHTERـFREE_BUY && <SlaughterFreeBuy />}
              {pathname === ROUTE_SLAUGHTERـEXPORT && <SlaughterExport />}
            </Grid>

            {pathname === ROUTE_SLAUGHTER_ALLOCATION_REQUESTS && (
              <ProvinceAllocatedRequests />
            )}
          </Grid>
        </Grid>
      </Box>
    </>
  );
};

export default SlaughterRequestsPage;
