import { format } from "date-fns-jalali";
import { useEffect, useState } from "react";
import { SimpleTable } from "../../../../components/simple-table/SimpleTable";

export const SlaughterUnpaidFeesDetails = ({ item }) => {
  const [dataTable, setDataTable] = useState([]);

  useEffect(() => {
    const d = item?.killHouseRequests?.map((item) => {
      const vetfarm = item?.vetFarm?.vet?.user?.fullname
        ? item?.vetFarm?.vet?.user?.fullname +
          `(${item?.vetFarm?.vet?.user?.mobile})`
        : "فاقد دامپزشک";

      let state = "";
      if (item.vetState === "accepted") {
        state = "تایید تخلیه";
      } else if (item.vetState === "pending") {
        state = "در انتظار تخلیه";
      }
      return [
        item.barCode,
        `${item.killhouseUser?.name} (${item.killhouseUser?.killHouseOperator?.user?.mobile})`,
        `${item.addCar.driver.typeCar} ${item.addCar.driver.pelak}`,
        `${item.addCar.driver.driverName} (${item.addCar.driver.driverMobile})`,
        item?.trafficCode,
        item.poultryRequest.chickenBreed,
        item.quantity?.toLocaleString(),
        item?.weightInfo?.weight?.toLocaleString(),
        item?.weightInfo?.indexWeight?.toLocaleString(),
        `${item.poultryRequest?.poultry?.unitName} (${item.poultryRequest.poultry?.user?.mobile})`,
        vetfarm,
        item?.clearanceCode ? item?.clearanceCode : "-",
        item.killPlace,
        item.poultryRequest.poultry.address.city.name,
        item?.poultryRequest.sendDate
          ? format(new Date(item?.poultryRequest.sendDate), "yyyy/MM/dd")
          : "-",
        item?.poultryRequest.orderCode,
        state,
      ];
    });
    setDataTable(d);
  }, [item]);

  return (
    <SimpleTable
      columns={[
        "کدبار",
        "خریدار",
        "ماشین",
        "راننده",
        "کدبهداشتی حمل و نقل",
        "نژاد",
        "تعداد",
        "وزن بار",
        "میانگین وزن",
        "مرغدار",
        "دامپزشک فارم",
        "کدرهگیری سامانه قرنطینه",
        "محل کشتار",
        "شهر",
        "تاریخ کشتار",
        "کدسفارش کشتار",
        "وضعیت",
      ]}
      data={dataTable}
    />
  );
};
