import { CircularProgress, Typography } from "@mui/material";
import { useEffect, useState } from "react";
import { useSelector } from "react-redux";
import { Grid } from "../../components/grid/Grid";
import { getRoleFromUrl } from "../../utils/getRoleFromUrl";

export const KillRequestsStats = ({ province }) => {
  const [data, setData] = useState([]);
  const [loading, setLoading] = useState(false);
  const { authToken } = useSelector((state) => state.userSlice);

  useEffect(() => {
    fetch(
      `${province}total_poultry_request_dashboard/?role=${getRoleFromUrl()}`,
      {
        headers: {
          Authorization: `Bearer ${authToken}`,
        },
      }
    )
      .then((response) => response.json())
      .then((data) => {
        setData(data);
        setLoading(false);
      })
      .catch((error) => {
        console.error("Error fetching data:", error);
        setLoading(false);
      });
  }, [province]);

  return (
    <>
      {loading ? (
        <CircularProgress />
      ) : (
        <Grid
          container
          direction="column"
          justifyContent="center"
          alignItems="center"
        >
          {/* <img
            src="https://th.bing.com/th/id/OIG.YLx3XTohSvmSEVb4Ique?w=270&h=270&c=6&r=0&o=5&pid=ImgGn"
            width={200}
          /> */}
          <Typography my={2} fontWeight={"bold"}>
            درخواست های کشتار
          </Typography>
          <Grid container direction="column" alignItems="start">
            <Typography color="primary" variant="body2" mb={1}>
              کل درخواست ها:{" "}
              {data?.total_poultry_request_quantity?.toLocaleString()} قطعه
            </Typography>
            <Typography color="primary" variant="body2" mb={1}>
              تایید شده:{" "}
              {data?.accepted_poultry_request_quantity?.toLocaleString()} قطعه
            </Typography>
            <Typography color="primary" variant="body2" mb={1}>
              کل بارها:{" "}
              {data?.total_kill_house_request_quantity?.toLocaleString()} قطعه
            </Typography>
            <Typography color="primary" variant="body2" mb={1}>
              تخلیه شده:{" "}
              {data?.accepted_kill_house_request_quantity?.toLocaleString()}{" "}
              قطعه
            </Typography>
          </Grid>
        </Grid>
      )}
    </>
  );
};
