import moment from "moment/moment";
import { format } from "date-fns-jalali";

export const getSlaughterHousesForSelect = (slaughterHouses) => {
  return slaughterHouses
    .filter((item) => item.remainQuantity > 0)
    .map((item, i) => {
      const requestedHighWeight = item?.weightType?.highWeight
        ? "بالای 2.5 کیلو"
        : null;
      const requestedLowWeight = item?.weightType?.lowWeight
        ? "بین 2 تا 2.5 کیلو"
        : null;
      const requestedWeight = [requestedLowWeight, requestedHighWeight]
        .filter((item) => item)
        .join(" و ");
      const requestedBuyTypeCash = item.buyType?.cash ? "نقدی" : null;
      const requestedBuyTypeCredit = item.buyType?.credit ? "زمان دار" : null;
      const requestedBuyType = [requestedBuyTypeCash, requestedBuyTypeCredit]
        .filter((item) => item)
        .join(" یا ");

      return {
        label: `${item.killHouse.name} (${
          item.killHouse.killHouseOperator.user.fullname
        }) - تاریخ کشتار ${format(
          new Date(moment(new Date(item.reciveDate)).format("YYYY-MM-DD")),
          "yyyy/MM/dd"
        )} با تعداد مانده درخواست ${
          item.remainQuantity
        } قطعه با وزن درخواستی: ${requestedWeight} و پرداخت بصورت ${requestedBuyType}`,
        key: item.key,
        remainQuantity: item.remainQuantity,
        requestedWeight: requestedWeight,
        requestedBuyType: requestedBuyType,
      };
    });
};
