import { Card } 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_PROVINCE_FILE } from "../../../../routes/routes";
import IconButton from "@mui/material/IconButton";
import { useDispatch, useSelector } from "react-redux";
import { provinceGetRejectedRequests } from "../../services/province-get-rejected-requests";
import { formatJustDate } from "../../../../utils/formatTime";

export const ProvinceRejectedRequests = () => {
  const navigate = useNavigate();
  const dispatch = useDispatch();
  const { provinceRejectedRequests } = useSelector(
    (state) => state.provinceSlice
  );
  const [dataTable, setDataTable] = useState([]);

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

  useEffect(() => {
    const d = provinceRejectedRequests?.map((item, i) => {
      return [
        i + 1,
        item.orderCode,
        formatJustDate(item?.createDate),
        formatJustDate(item?.sendDate),
        item.fullname,
        item.mobile,
        item.city,
        item.province,
        item.poultryQuantity,
        <IconButton
          key={i}
          aria-label="delete"
          color="primary"
          onClick={() => {
            navigate(ROUTE_PROVINCE_FILE + item.id);
          }}
        >
          <PlagiarismIcon />
        </IconButton>,
      ];
    });
    setDataTable(d);
  }, [provinceRejectedRequests]);

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