import { Card, IconButton } from "@mui/material";
import { useEffect, useState } from "react";
import { AdvancedTable } from "../../../../components/advanced-table/AdvancedTable";
import PlagiarismIcon from "@mui/icons-material/Plagiarism";
import { useNavigate } from "react-router-dom";
import { ROUTE_CITY_FILE } from "../../../../routes/routes";
import { FileInformation } from "../../../file/components/file-information/FileInformation";
import useAvicultureRequests from "../../../aviculture/hooks/useAvicultureRequests";
import { formatJustDate } from "../../../../utils/formatTime";

export const CityRejectedRequests = () => {
  const navigate = useNavigate();

  const [dataTable, setDataTable] = useState([]);
  const avicultureRequests = useAvicultureRequests("CityOperator");
  useEffect(() => {
    const filteredData = avicultureRequests?.filter(
      (item, i) => item.stateProcess === "rejected"
    );
    const d = filteredData?.map((item, i) => {
      return [
        i + 1,
        item.orderCode,
        formatJustDate(item?.createDate),
        formatJustDate(item?.sendDate),
        item?.process?.poultry?.poultryName,
        item?.process?.poultry?.poultryMobile,
        item?.process?.poultry?.poultryCity,
        item?.process?.poultry?.poultryProvince,
        item?.process?.poultry?.age,
        item?.process?.poultry?.poultryQuantity,
        <IconButton
          key={i}
          aria-label="delete"
          color="primary"
          onClick={() =>
            navigate(ROUTE_CITY_FILE + item?.process?.poultry?.poultryRequestId)
          }
        >
          <PlagiarismIcon />
        </IconButton>,
      ];
    });

    setDataTable(d);
  }, []);

  const [tableDataCol] = useState([
    "ردیف",
    "کد سفارش",
    "تاریخ ثبت درخواست",
    "تاریخ درخواست",
    "مرغدار",
    "تلفن مرغدار",
    "شهر",
    "استان",
    "سن مرغ",
    "تعداد",
    "مشاهده",
  ]);
  return (
    <Card>
      <AdvancedTable
        expandable
        name={"درخواست های رد شده"}
        columns={tableDataCol}
        expandedComponentHandler={(rowData) => (
          <FileInformation id={rowData[0]} />
        )}
        data={dataTable}
      />
    </Card>
  );
};
