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

export const CityInformationContent = ({ file }) => {
  const [cityInfoData, setCityInfo] = useState({
    cityOperatorName: "اپراتور شهرستان",
    cityOperatorMobile: "-",
    cityUnionName: "-",
    acceptedRejectedDate: "",
    cityState: "در انتظار تایید",
  });

  const { city, cityOperator } = file;
  useEffect(() => {
    let cityOperatorName,
      cityOperatorMobile,
      acceptedRejectedDate,
      cityState,
      cityUnionName;
    if (city) {
      cityOperatorName = city.cityOperatorName;
      cityOperatorMobile = city.cityOperatorMobile;
      acceptedRejectedDate = city.acceptedRejectedDate;
      cityUnionName = city.unitName;
      cityState = city.cityState === "accept" ? "تایید شده" : "رد شده";
    } else {
      cityOperatorName = cityOperator?.cityOperatorName;
      cityOperatorMobile = cityOperator.cityOperatorMobile;
      cityUnionName = cityOperator.unitName;
      acceptedRejectedDate = null;
      cityState = "در انتظار تایید";
    }
    setCityInfo({
      cityOperatorName,
      cityOperatorMobile,
      acceptedRejectedDate,
      cityUnionName,
      cityState,
    });
  }, [city]);

  return (
    <Grid xs={12}>
      <SimpleTable
        columns={[
          "نام اپراتور",
          "نام اتحادیه",
          "تلفن",
          "استان",
          "شهر",
          "تاریخ بررسی",
          "وضعیت",
          city?.cityOperatorMessage ? "دلیل رد" : "",
        ]}
        data={[
          [
            cityInfoData.cityOperatorName,
            cityInfoData.cityUnionName,
            cityInfoData.cityOperatorMobile,
            cityOperator.cityOperatorProvince,
            cityOperator.cityOperatorCity,
            format(new Date(cityInfoData.acceptedRejectedDate), "yyyy/MM/dd"),
            city?.provinceAccept
              ? "تایید شده توسط استان"
              : cityInfoData.cityState,
            city?.cityOperatorMessage ? city?.cityOperatorMessage : "",
          ],
        ]}
      />
    </Grid>
  );
};

CityInformationContent.propTypes = {
  file: PropTypes.any,
};
