import { Box, Card } from "@mui/material";
import { Grid } from "../components/grid/Grid";
import { SPACING } from "../data/spacing";
import { useLocation } from "react-router-dom";
import { AvicultureNewRequest } from "../features/aviculture/components/aviculture-new-request/AvicultureNewRequest";
import { AvicultureActiveRequests } from "../features/aviculture/components/aviculture-active-requests/AvicultureActiveRequests";
import { useDispatch } from "react-redux";
import { useEffect } from "react";
import { avicultureGetRequests } from "../features/aviculture/services/aviculture-requests";
import { AvicultureRejectedRequests } from "../features/aviculture/components/aviculture-rejected-requests/AvicultureRejectedRequests";
import { AvicultureArchivedRequests } from "../features/aviculture/components/aviculture-archived-requests/AvicultureArchivedRequests";
import { RequestsAwaitingPayment } from "../components/requests-awaiting-payment/RequestsAwaitingPayment";
import { RequestsAwaitingInspections } from "../components/requests-awaiting-inspections/RequestsAwaitingInspections";
import {
  ROUTE_ADMIN_ARCHIVED_REQUESTS,
  ROUTE_ADMIN_AWAITING_INSPECTION_REQUESTS,
  ROUTE_ADMIN_AWAITING_PAYMENT_REQUESTS,
  ROUTE_ADMIN_CREATE_NEW_REQUEST,
  ROUTE_ADMIN_HATCHING,
  ROUTE_ADMIN_REJECTED_REQUESTS,
  ROUTE_ADMIN_REQUESTS,
} from "../routes/routes";
import { AdminRequestsOperations } from "../features/admin/components/requests-operations/AdminRequestsOperations";
import { AdminHatching } from "../features/admin/components/admin-hatching/AdminHatching";

const AdminRequests = () => {
  const { pathname } = useLocation();
  const dispatch = useDispatch();

  useEffect(() => {
    dispatch(avicultureGetRequests());
  }, []);

  return (
    <Box display={"flex"} justifyContent="center">
      <Grid
        container
        direction="column"
        justifyContent="center"
        xs={12}
        sm={12}
        md={10}
        lg={10}
      >
        <Grid justifyContent="center" my={SPACING.MEDIUM}>
          <Card>
            <AdminRequestsOperations />
          </Card>
        </Grid>
        <Grid container justifyContent="space-between" gap={SPACING.SMALL}>
          <Grid xs={12}>
            {pathname === ROUTE_ADMIN_CREATE_NEW_REQUEST && (
              <AvicultureNewRequest />
            )}
            {pathname === ROUTE_ADMIN_HATCHING && <AdminHatching />}
            {pathname === ROUTE_ADMIN_REQUESTS && <AvicultureActiveRequests />}
            {pathname === ROUTE_ADMIN_REJECTED_REQUESTS && (
              <AvicultureRejectedRequests />
            )}
            {pathname === ROUTE_ADMIN_ARCHIVED_REQUESTS && (
              <AvicultureArchivedRequests />
            )}
            {pathname === ROUTE_ADMIN_AWAITING_PAYMENT_REQUESTS && (
              <RequestsAwaitingPayment />
            )}

            {pathname === ROUTE_ADMIN_AWAITING_INSPECTION_REQUESTS && (
              <RequestsAwaitingInspections />
            )}
          </Grid>
        </Grid>
      </Grid>
    </Box>
  );
};

export default AdminRequests;
