import {
  Button,
  FormControlLabel,
  IconButton,
  Switch,
  Tooltip,
  Typography,
} from "@mui/material";
import React from "react";
import { useEffect } from "react";
import { useNavigate, useParams } from "react-router-dom";
import { Grid } from "../../../../components/grid/Grid";
import NavigateNextIcon from "@mui/icons-material/NavigateNext";
import { useDispatch, useSelector } from "react-redux";
import { provinceGetUserByKey } from "../../../province/services/province-get-user-by-key";
import { useState } from "react";
import { SPACING } from "../../../../data/spacing";
import { SimpleTable } from "../../../../components/simple-table/SimpleTable";
import EditIcon from "@mui/icons-material/Edit";

import {
  DRAWER,
  LOADING_END,
  LOADING_START,
} from "../../../../lib/redux/slices/appSlice";
import { inspectorChangeUserState } from "../../services/inspector-change-user-state";
import { InspectorEditUserProfile } from "../inspector-edit-user-profile/InspectorEditUserProfile";
import { InspectorEditOperator } from "../inspector-edit-operator/InspectorEditOperator";
import { InspectorEditKillHouseVet } from "../inspector-edit-killhouse-vet/InspectorEditKillHousevet";
import { InspectorEditDriver } from "../inspector-edit-driver/InspectorEditDriver";
import { CitySubmitTenantForm } from "../../../city/components/city-submit-tenant-form/CitySubmitTenantForm";
// import { inspectorUpdateUserProfile } from "../../services/inspector-update-user-profile";
import InfoIcon from "@mui/icons-material/Info";
import { InspectorEditAviculture } from "../inspector-edit-aviculture/InspectorEditAviculture";
import { format } from "date-fns-jalali";
import { ProvinceEditTenant } from "../province-edit-tenant/ProvinceEditTenant";

export const ProvinceUserFileInfo = () => {
  const { userid } = useParams();
  const dispatch = useDispatch();
  const navigate = useNavigate();
  const [dataTable, setDataTable] = useState([]);

  const { provinceUserInfo } = useSelector((state) => state.provinceSlice);

  useEffect(() => {
    dispatch(LOADING_START());
    dispatch(provinceGetUserByKey(userid)).then((r) => {
      dispatch(LOADING_END());
    });
  }, []);

  const updateData = () => {
    dispatch(provinceGetUserByKey(userid)).then((r) => {
      dispatch(LOADING_END());
    });
  };

  useEffect(() => {
    const userRoles = provinceUserInfo?.profile?.role?.map((item, i) => {
      let name = "";
      switch (item) {
        case "ProvinceOperator":
          name = "اپراتور تخصیص استان";
          break;
        case "CityOperator":
          name = "اپراتور شهرستان";
          break;
        case "KillHouseVet":
          name = "دامپزشک کشتارگاه";
          break;
        case "VetFarm":
          name = "دامپزشک";
          break;
        case "Poultry":
          name = "مرغدار";
          break;
        case "KillHouse":
          name = "کشتارگاه";
          break;
        case "Vet":
          name = "دامپزشک";
          break;
        case "ProvinceInspector":
          name = "بازرس استان";
          break;
        case "ProvinceFinancial":
          name = "اپراتور مالی";
          break;
        case "Driver":
          name = "راننده";
          break;
        case "Admin":
          name = "ادمین";
          break;
        default:
          name = "کاربر پایه";
          break;
      }
      return <div key={i}>{name}</div>;
    });

    const userProfilePic =
      provinceUserInfo?.profile?.image?.length > 5 ? (
        <a href={provinceUserInfo?.profile.image}>
          <img
            width="80"
            height="80"
            alt="img"
            src={provinceUserInfo?.profile.image}
          />
        </a>
      ) : (
        "موجود نیست"
      );
    const b = [
      [
        provinceUserInfo?.profile?.fullname
          ? provinceUserInfo?.profile?.fullname
          : provinceUserInfo?.profile?.firstName +
            " " +
            provinceUserInfo?.profile?.lastName,
        userRoles,
        provinceUserInfo?.profile?.mobile,
        provinceUserInfo?.profile?.birthday
          ? format(new Date(provinceUserInfo?.profile?.birthday), "yyyy/MM/dd")
          : "نامشخص",
        provinceUserInfo?.profile?.city,
        <Typography variant="caption" key="password">
          {provinceUserInfo?.profile?.password}
        </Typography>,
        userProfilePic,
        <IconButton
          key={provinceUserInfo}
          aria-label="delete"
          color="primary"
          className="avicultureActiveRequestsBtn"
          onClick={() => {
            // dispatch(inspectorUpdateUserProfile());
            dispatch(
              DRAWER({
                title: "ویرایش پروفایل کاربر",
                right: !(window.innerWidth <= 600),
                bottom: window.innerWidth <= 600,
                content: (
                  <InspectorEditUserProfile
                    id={provinceUserInfo?.profile?.key}
                    birthday={provinceUserInfo?.profile?.birthday}
                    nationalCode={provinceUserInfo?.profile?.nationalCode}
                    nationalId={provinceUserInfo?.profile?.nationalId}
                    firstName={provinceUserInfo?.profile?.firstName}
                    lastName={provinceUserInfo?.profile?.lastName}
                    password={provinceUserInfo?.profile?.password}
                    phone={provinceUserInfo?.profile?.mobile}
                  />
                ),
              })
            );
          }}
        >
          <EditIcon />
        </IconButton>,
      ],
    ];

    setDataTable(b);
  }, [provinceUserInfo]);

  return (
    <>
      <Grid container alignItems="center" mt={SPACING.SMALL}>
        <IconButton
          aria-label="delete"
          color="primary"
          onClick={() => navigate(-1)}
        >
          <NavigateNextIcon />
          <Typography>بازگشت</Typography>
        </IconButton>
      </Grid>

      <Grid
        container
        xs={12}
        alignItems={"start"}
        gap={SPACING.SMALL}
        direction={"column"}
      >
        <Grid
          width="100%"
          container
          alignItems="center"
          justifyContent="space-between"
        >
          <Grid width="100%" className="second">
            <SimpleTable
              name="اطلاعات پایه کاربر"
              columns={[
                "نام کامل",
                "نوع کاربری",
                "شمار تلفن",
                "تاریخ تولد",
                "شهر",
                "کلمه عبور",
                "تصویر پروفایل",
                "ویرایش",
              ]}
              data={dataTable}
            />

            {provinceUserInfo?.rolesData?.map((item, i) => {
              if (Object.keys(item).includes("ProvinceOperator")) {
                return (
                  <>
                    <SimpleTable
                      key={i}
                      name="اطلاعات اپراتور استان"
                      columns={[
                        "آدرس",
                        "استان",
                        "شهر",
                        "کد پستی",
                        "موبایل",
                        "ویرایش",
                        "وضعیت",
                      ]}
                      data={[
                        [
                          item.ProvinceOperator.address?.address,
                          item.ProvinceOperator.address?.province.name,
                          item.ProvinceOperator.address?.city.name,
                          Number(item.ProvinceOperator.address?.postalCode),
                          item.ProvinceOperator.address?.phone,

                          <Tooltip
                            key={i}
                            title={"ویرایش کاربر"}
                            placement="bottom-start"
                          >
                            <IconButton
                              aria-label="delete"
                              color="primary"
                              className="avicultureActiveRequestsBtn"
                              onClick={() => {
                                dispatch(
                                  DRAWER({
                                    title: "ویرایش اطلاعات اپراتور",
                                    right: !(window.innerWidth <= 600),
                                    bottom: window.innerWidth <= 600,
                                    content: (
                                      <InspectorEditOperator
                                        id={provinceUserInfo?.profile.key}
                                        type="ProvinceOperator"
                                        address={
                                          item.ProvinceOperator.address?.address
                                        }
                                        postal={Number(
                                          item.ProvinceOperator.address
                                            ?.postalCode
                                        )}
                                      />
                                    ),
                                  })
                                );
                              }}
                            >
                              <EditIcon />
                            </IconButton>
                          </Tooltip>,
                          <Tooltip
                            key={i}
                            title={
                              item.ProvinceOperator.trash === true
                                ? "فعالسازی کاربر"
                                : "غیر فعال کردن کاربر"
                            }
                            placement="bottom-start"
                          >
                            <FormControlLabel
                              label={
                                item.ProvinceOperator.trash === true
                                  ? "غیرفعال"
                                  : " فعال"
                              }
                              control={
                                <Switch
                                  checked={!item.ProvinceOperator.trash}
                                  onClick={() => {
                                    dispatch(LOADING_START());
                                    dispatch(
                                      inspectorChangeUserState({
                                        type:
                                          item.ProvinceOperator.trash === true
                                            ? "Activate"
                                            : "Deactivate",
                                        role_data_key:
                                          item.ProvinceOperator.key,
                                        role: "ProvinceOperator",
                                      })
                                    ).then((r) => {
                                      dispatch(LOADING_END());
                                      window.location.reload(false);
                                    });
                                  }}
                                />
                              }
                            />
                          </Tooltip>,
                        ],
                      ]}
                    />
                  </>
                );
              } else if (Object.keys(item).includes("ProvinceInspector")) {
                return (
                  <SimpleTable
                    key={i}
                    name="اطلاعات بازرس استان"
                    expandable
                    columns={[
                      "آدرس",
                      "استان",
                      "شهر",
                      "کد پستی",
                      "موبایل",
                      "ویرایش",
                      "وضعیت",
                    ]}
                    data={[
                      [
                        item.ProvinceInspector.address?.address,
                        item.ProvinceInspector.address?.province.name,
                        item.ProvinceInspector.address?.city.name,
                        Number(item.ProvinceInspector.address?.phone),
                        <Tooltip
                          key={i}
                          title={"ویرایش کاربر"}
                          placement="bottom-start"
                        >
                          <IconButton
                            aria-label="delete"
                            color="primary"
                            className="avicultureActiveRequestsBtn"
                            onClick={() => {
                              dispatch(
                                DRAWER({
                                  title: "ویرایش اطلاعات بازرس استان",
                                  right: !(window.innerWidth <= 600),
                                  bottom: window.innerWidth <= 600,
                                  content: (
                                    <InspectorEditOperator
                                      id={provinceUserInfo?.profile.key}
                                      type="ProvinceInspector"
                                      address={
                                        item.ProvinceInspector.address?.address
                                      }
                                      postal={Number(
                                        item.ProvinceInspector?.address
                                          ?.postalCode
                                      )}
                                    />
                                  ),
                                })
                              );
                            }}
                          >
                            <EditIcon />
                          </IconButton>
                        </Tooltip>,
                        <Tooltip
                          key={i}
                          title={
                            item.ProvinceInspector?.trash === true
                              ? "فعالسازی کاربر"
                              : "غیر فعال کردن کاربر"
                          }
                          placement="bottom-start"
                        >
                          <FormControlLabel
                            label={
                              item.ProvinceInspector?.trash === true
                                ? "غیرفعال"
                                : " فعال"
                            }
                            control={
                              <Switch
                                checked={!item.ProvinceInspector?.trash}
                                onClick={() => {
                                  dispatch(LOADING_START());
                                  dispatch(
                                    inspectorChangeUserState({
                                      type:
                                        item.ProvinceInspector.trash === true
                                          ? "Activate"
                                          : "Deactivate",
                                      role_data_key: item.ProvinceInspector.key,
                                      role: "ProvinceInspector",
                                    })
                                  ).then((r) => {
                                    dispatch(LOADING_END());
                                    window.location.reload(false);
                                  });
                                }}
                              />
                            }
                          />
                        </Tooltip>,
                      ],
                    ]}
                  />
                );
              } else if (Object.keys(item).includes("CityOperator")) {
                return (
                  <>
                    <SimpleTable
                      key={i}
                      name="اطلاعات اپراتور شهرستان"
                      expandable
                      columns={[
                        "آدرس",
                        "استان",
                        "شهر",
                        "کد پستی",
                        "موبایل",
                        "ویرایش",
                        "وضعیت",
                      ]}
                      data={[
                        [
                          item.CityOperator.address?.address,
                          item.CityOperator.address?.province?.name,
                          item.CityOperator.address?.city?.name,
                          Number(item.CityOperator.address?.postalCode),
                          item.CityOperator.address?.phone,
                          <Tooltip
                            key={i}
                            title={"ویرایش کاربر"}
                            placement="bottom-start"
                          >
                            <IconButton
                              aria-label="delete"
                              color="primary"
                              className="avicultureActiveRequestsBtn"
                              onClick={() => {
                                dispatch(
                                  DRAWER({
                                    title: "ویرایش اطلاعات اپراتور",
                                    right: !(window.innerWidth <= 600),
                                    bottom: window.innerWidth <= 600,
                                    content: (
                                      <InspectorEditOperator
                                        id={provinceUserInfo?.profile.key}
                                        type="CityOperator"
                                        address={
                                          item.CityOperator.address?.address
                                        }
                                        postal={Number(
                                          item.CityOperator.address?.postalCode
                                        )}
                                        accountHolder={
                                          item.CityOperator.userBankInfo
                                            ?.nameOfBankUser
                                        }
                                        card={
                                          item.CityOperator.userBankInfo?.card
                                        }
                                        shaba={
                                          item.CityOperator.userBankInfo?.shaba
                                        }
                                        account={
                                          item.CityOperator?.userBankInfo
                                            ?.account
                                        }
                                        name_of_bank_user={
                                          item.CityOperator?.userBankInfo
                                            ?.bankName
                                        }
                                      />
                                    ),
                                  })
                                );
                              }}
                            >
                              <EditIcon />
                            </IconButton>
                          </Tooltip>,
                          <Tooltip
                            key={i}
                            title={
                              item.CityOperator?.trash === true
                                ? "فعالسازی کاربر"
                                : "غیر فعال کردن کاربر"
                            }
                            placement="bottom-start"
                          >
                            <FormControlLabel
                              label={
                                item.CityOperator?.trash === true
                                  ? "غیرفعال"
                                  : " فعال"
                              }
                              control={
                                <Switch
                                  checked={!item.CityOperator.trash}
                                  onClick={() => {
                                    dispatch(LOADING_START());
                                    dispatch(
                                      inspectorChangeUserState({
                                        type:
                                          item.CityOperator.trash === true
                                            ? "Activate"
                                            : "Deactivate",
                                        role_data_key: item.CityOperator.key,
                                        role: "CityOperator",
                                      })
                                    ).then((r) => {
                                      dispatch(LOADING_END());
                                      window.location.reload(false);
                                    });
                                  }}
                                />
                              }
                            />
                          </Tooltip>,
                        ],
                      ]}
                    />

                    <SimpleTable
                      key={i}
                      name="اطلاعات بانکی شهرستان"
                      expandable
                      columns={[
                        "نام صاحب حساب",
                        "نام بانک",
                        "شماره حساب",
                        "شماره کارت",
                        "شماره شبا",
                      ]}
                      data={[
                        [
                          item.CityOperator.userBankInfo?.nameOfBankUser,
                          item.CityOperator.userBankInfo?.bankName,
                          Number(item.CityOperator.userBankInfo?.account),
                          Number(item.CityOperator.userBankInfo?.card),
                          item.CityOperator.userBankInfo?.shaba,
                        ],
                      ]}
                    />
                  </>
                );
              } else if (Object.keys(item).includes("VetFarm")) {
                return (
                  <>
                    <SimpleTable
                      key={i}
                      name="اطلاعات دامپزشک فارم"
                      expandable
                      columns={[
                        "آدرس",
                        "استان",
                        "شهر",
                        "کد پستی",
                        "موبایل",
                        "ویرایش",
                        "وضعیت",
                      ]}
                      data={[
                        [
                          item.VetFarm.address?.address,
                          item.VetFarm.address?.province.name,
                          item.VetFarm.address?.city.name,
                          Number(item.VetFarm.address?.postalCode),
                          item.VetFarm.address?.phone,
                          <Tooltip
                            key={i}
                            title={"ویرایش کاربر"}
                            placement="bottom-start"
                          >
                            <IconButton
                              aria-label="delete"
                              color="primary"
                              className="avicultureActiveRequestsBtn"
                              onClick={() => {
                                dispatch(
                                  DRAWER({
                                    title: "ویرایش اطلاعات اپراتور",
                                    right: !(window.innerWidth <= 600),
                                    bottom: window.innerWidth <= 600,
                                    content: (
                                      <InspectorEditOperator
                                        id={provinceUserInfo?.profile?.key}
                                        type="VetFarm"
                                        address={item.VetFarm.address?.address}
                                        postal={Number(
                                          item.VetFarm.address?.postalCode
                                        )}
                                        accountHolder={
                                          item.VetFarm.userBankInfo
                                            ?.nameOfBankUser
                                        }
                                        card={item.VetFarm.userBankInfo?.card}
                                        shaba={item.VetFarm.userBankInfo?.shaba}
                                        account={
                                          item.VetFarm.userBankInfo?.account
                                        }
                                        name_of_bank_user={
                                          item.VetFarm.userBankInfo?.bankName
                                        }
                                      />
                                    ),
                                  })
                                );
                              }}
                            >
                              <EditIcon />
                            </IconButton>
                          </Tooltip>,
                          <Tooltip
                            key={i}
                            title={
                              item.VetFarm.trash === true
                                ? "فعالسازی کاربر"
                                : "غیر فعال کردن کاربر"
                            }
                            placement="bottom-start"
                          >
                            <FormControlLabel
                              label={
                                item.VetFarm?.trash === true
                                  ? "غیرفعال"
                                  : " فعال"
                              }
                              control={
                                <Switch
                                  checked={!item.VetFarm?.trash}
                                  onClick={() => {
                                    dispatch(LOADING_START());
                                    dispatch(
                                      inspectorChangeUserState({
                                        type:
                                          item.VetFarm.trash === true
                                            ? "Activate"
                                            : "Deactivate",
                                        role_data_key: item.VetFarm.key,
                                        role: "Vet",
                                      })
                                    ).then((r) => {
                                      dispatch(LOADING_END());
                                      window.location.reload(false);
                                    });
                                  }}
                                />
                              }
                            />
                          </Tooltip>,
                        ],
                      ]}
                    />

                    <SimpleTable
                      key={i}
                      name="اطلاعات بانکی دامپزشک فارم"
                      expandable
                      columns={[
                        "نام صاحب حساب",
                        "نام بانک",
                        "شماره حساب",
                        "شماره کارت",
                        "شماره شبا",
                      ]}
                      data={[
                        [
                          item.VetFarm.userBankInfo?.nameOfBankUser,
                          item.VetFarm.userBankInfo?.bankName,
                          Number(item.VetFarm.userBankInfo?.account),
                          Number(item.VetFarm.userBankInfo?.card),
                          item.VetFarm.userBankInfo?.shaba,
                        ],
                      ]}
                    />
                  </>
                );
              } else if (Object.keys(item).includes("KillHouse")) {
                return (
                  <>
                    {" "}
                    <SimpleTable
                      key={i}
                      name="اطلاعات کشتارگاه"
                      expandable
                      columns={[
                        "آدرس",
                        "استان",
                        "شهر",
                        "کد پستی",
                        "موبایل",
                        "ویرایش",
                        "وضعیت",
                      ]}
                      data={[
                        [
                          item.KillHouse.address?.address,
                          item.KillHouse.address?.province?.name,
                          item.KillHouse.address?.city?.name,
                          Number(item.KillHouse.address?.postalCode),
                          item.KillHouse.address?.phone,

                          <Tooltip
                            key={i}
                            title={"ویرایش کاربر"}
                            placement="bottom-start"
                          >
                            <IconButton
                              aria-label="delete"
                              color="primary"
                              className="avicultureActiveRequestsBtn"
                              onClick={() => {
                                dispatch(
                                  DRAWER({
                                    title: "ویرایش اطلاعات کشتارگاه",
                                    right: !(window.innerWidth <= 600),
                                    bottom: window.innerWidth <= 600,
                                    content: (
                                      <InspectorEditOperator
                                        id={provinceUserInfo?.profile?.key}
                                        type="KillHouse"
                                        address={
                                          item.KillHouse.address?.address
                                        }
                                        postal={Number(
                                          item.KillHouse.address?.postalCode
                                        )}
                                        accountHolder={
                                          item.KillHouse.userBankInfo
                                            ?.nameOfBankUser
                                        }
                                        card={item.KillHouse.userBankInfo?.card}
                                        shaba={
                                          item.KillHouse.userBankInfo?.shaba
                                        }
                                        account={
                                          item.KillHouse.userBankInfo?.account
                                        }
                                        name_of_bank_user={
                                          item.KillHouse.userBankInfo?.bankName
                                        }
                                      />
                                    ),
                                  })
                                );
                              }}
                            >
                              <EditIcon />
                            </IconButton>
                          </Tooltip>,
                          <Tooltip
                            key={i}
                            title={
                              item.KillHouse?.trash === true
                                ? "فعالسازی کاربر"
                                : "غیر فعال کردن کاربر"
                            }
                            placement="bottom-start"
                          >
                            <FormControlLabel
                              label={
                                item.KillHouse.trash === true
                                  ? "غیرفعال"
                                  : " فعال"
                              }
                              control={
                                <Switch
                                  checked={!item.KillHouse?.trash}
                                  onClick={() => {
                                    dispatch(LOADING_START());
                                    dispatch(
                                      inspectorChangeUserState({
                                        type:
                                          item.KillHouse?.trash === true
                                            ? "Activate"
                                            : "Deactivate",
                                        role_data_key: item.KillHouse?.key,
                                        role: "KillHouse",
                                      })
                                    ).then((r) => {
                                      dispatch(LOADING_END());
                                      window.location.reload(false);
                                    });
                                  }}
                                />
                              }
                            />
                          </Tooltip>,
                        ],
                      ]}
                    />
                    <SimpleTable
                      key={i}
                      name="اطلاعات بانکی کشتارگاه"
                      expandable
                      columns={[
                        "نام صاحب حساب",
                        "نام بانک",
                        "شماره حساب",
                        "شماره کارت",
                        "شماره شبا",
                      ]}
                      data={[
                        [
                          item.KillHouse.userBankInfo?.nameOfBankUser,
                          item.KillHouse.userBankInfo?.bankName,
                          Number(item.KillHouse.userBankInfo?.account),
                          Number(item.KillHouse.userBankInfo?.card),
                          item.KillHouse.userBankInfo?.shaba,
                        ],
                      ]}
                    />
                  </>
                );
              } else if (Object.keys(item).includes("Poultry")) {
                return (
                  <>
                    <SimpleTable
                      key={i}
                      name="اطلاعات مرغدار"
                      columns={[
                        "نام فارم",
                        "آدرس",
                        "استان",
                        "شهر",
                        "کد پستی",
                        "موبایل",
                        "شناسه یکتا",
                        "کد اقتصادی",
                        "کد اپیدمیولوژیک",
                        "تعداد سالن",
                        "ویرایش",
                        "وضعیت",
                      ]}
                      data={[
                        [
                          item.Poultry?.unitName,
                          item.Poultry.address?.address,
                          item.Poultry.address?.province?.name,
                          item.Poultry.address?.city?.name,
                          Number(item.Poultry.address?.postalCode),
                          item.Poultry.address?.phone,
                          Number(item.Poultry.breedingUniqueId),
                          item.Poultry.economicCode,
                          item.Poultry.epidemiologicalCode,
                          item.Poultry.numberOfHalls,

                          <Tooltip
                            key={i}
                            title={"ویرایش کاربر"}
                            placement="bottom-start"
                          >
                            <IconButton
                              aria-label="delete"
                              color="primary"
                              className="avicultureActiveRequestsBtn"
                              onClick={() => {
                                dispatch(
                                  DRAWER({
                                    title: "ویرایش اطلاعات مرغدار",
                                    right: !(window.innerWidth <= 600),
                                    bottom: window.innerWidth <= 600,
                                    content: (
                                      <InspectorEditAviculture
                                        farmName={item.Poultry?.unitName}
                                        id={provinceUserInfo?.profile.key}
                                        type="Poultry"
                                        address={item.Poultry.address?.address}
                                        uniqueId={
                                          item.Poultry?.breedingUniqueId
                                        }
                                        poultry={item.Poultry?.key}
                                        halls={item.Poultry.numberOfHalls}
                                        postal={Number(
                                          item.Poultry.address?.postalCode
                                        )}
                                        accountHolder={
                                          item.Poultry.userBankInfo
                                            ?.nameOfBankUser
                                        }
                                        card={item.Poultry.userBankInfo?.card}
                                        shaba={item.Poultry.userBankInfo?.shaba}
                                        account={
                                          item.Poultry.userBankInfo?.account
                                        }
                                        name_of_bank_user={
                                          item.Poultry.userBankInfo?.bankName
                                        }
                                      />
                                    ),
                                  })
                                );
                              }}
                            >
                              <EditIcon />
                            </IconButton>
                          </Tooltip>,
                          <Tooltip
                            key={i}
                            title={
                              item.Poultry.trash === true
                                ? "فعالسازی کاربر"
                                : "غیر فعال کردن کاربر"
                            }
                            placement="bottom-start"
                          >
                            <FormControlLabel
                              label={
                                item.Poultry.trash === true
                                  ? "غیرفعال"
                                  : " فعال"
                              }
                              control={
                                <Switch
                                  checked={!item.Poultry.trash}
                                  onClick={() => {
                                    dispatch(LOADING_START());
                                    dispatch(
                                      inspectorChangeUserState({
                                        type:
                                          item.Poultry.trash === true
                                            ? "Activate"
                                            : "Deactivate",
                                        role_data_key: item.Poultry.key,
                                        role: "Poultry",
                                      })
                                    ).then((r) => {
                                      dispatch(LOADING_END());
                                      window.location.reload(false);
                                    });
                                  }}
                                />
                              }
                            />
                          </Tooltip>,
                        ],
                      ]}
                    />

                    <SimpleTable
                      key={i}
                      name="اطلاعات بانکی مرغدار"
                      expandable
                      columns={[
                        "نام صاحب حساب",
                        "نام بانک",
                        "شماره حساب",
                        "شماره کارت",
                        "شماره شبا",
                      ]}
                      data={[
                        [
                          item.Poultry.userBankInfo?.nameOfBankUser,
                          item.Poultry.userBankInfo?.bankName,
                          Number(item.Poultry.userBankInfo?.account),
                          Number(item.Poultry.userBankInfo?.card),
                          item.Poultry.userBankInfo?.shaba,
                        ],
                      ]}
                    />

                    {Object.keys(item.Poultry?.poultryTenant).length > 0 ? (
                      <SimpleTable
                        key={i}
                        name={
                          <Grid
                            container
                            alignItems="center"
                            gap={SPACING.TINY}
                          >
                            <Typography>اطلاعات مستاجر مرغدار</Typography>
                            <Button
                              onClick={() => {
                                dispatch(
                                  DRAWER({
                                    title: "ویرایش اطلاعات مستاجر",
                                    right: !(window.innerWidth <= 600),
                                    bottom: window.innerWidth <= 600,
                                    content: (
                                      <ProvinceEditTenant
                                        tenant={item.Poultry.poultryTenant}
                                        updateData={updateData}
                                      />
                                    ),
                                  })
                                );
                              }}
                            >
                              ویرایش
                            </Button>
                          </Grid>
                        }
                        expandable
                        columns={[
                          "شناسه یکتا",
                          "نام کامل",
                          "تلفن همراه",
                          "کد ملی",
                        ]}
                        data={[
                          [
                            item.Poultry.poultryTenant?.breedingUniqueId,
                            item.Poultry.poultryTenant?.fullName,
                            item.Poultry.poultryTenant?.mobile,
                            item.Poultry.poultryTenant?.nationalId,
                          ],
                        ]}
                      />
                    ) : (
                      !item.Poultry.poultryOwner.length > 0 && (
                        <Grid
                          display="flex"
                          mt={SPACING.MEDIUM}
                          gap={SPACING.SMALL}
                          alignItems="center"
                          mb={SPACING.MEDIUM}
                        >
                          <Grid display="flex" gap={SPACING.TINY}>
                            <InfoIcon color="primary" />
                            <Typography>مرغدار مستاجر ندارد</Typography>
                          </Grid>
                          <Button
                            variant="outlined"
                            onClick={() => {
                              dispatch(
                                DRAWER({
                                  right: !(window.innerWidth <= 600),
                                  bottom: window.innerWidth <= 600,
                                  title: "ایجاد مستاجر جدید",
                                  content: (
                                    <CitySubmitTenantForm
                                      id={item.Poultry.key}
                                      userid={userid}
                                    />
                                  ),
                                })
                              );
                            }}
                          >
                            افزودن مستاجر
                          </Button>
                        </Grid>
                      )
                    )}
                  </>
                );
              } else if (Object.keys(item).includes("ProvinceFinancial")) {
                return (
                  <>
                    <SimpleTable
                      key={i}
                      name="اطلاعات اپراتور مالی"
                      expandable
                      columns={[
                        "آدرس",
                        "استان",
                        "شهر",
                        "کد پستی",
                        "موبایل",
                        "ویرایش",
                        "وضعیت",
                      ]}
                      data={[
                        [
                          item.ProvinceFinancial.address?.address,
                          item.ProvinceFinancial.address?.province.name,
                          item.ProvinceFinancial.address?.city.name,
                          Number(item.ProvinceFinancial.address?.postalCode),
                          item.ProvinceFinancial.address?.phone,

                          <Tooltip
                            key={i}
                            title={"ویرایش کاربر"}
                            placement="bottom-start"
                          >
                            <IconButton
                              aria-label="delete"
                              color="primary"
                              className="avicultureActiveRequestsBtn"
                              onClick={() => {
                                dispatch(
                                  DRAWER({
                                    title: "ویرایش اطلاعات اپراتور مالی",
                                    right: !(window.innerWidth <= 600),
                                    bottom: window.innerWidth <= 600,
                                    content: (
                                      <InspectorEditOperator
                                        id={provinceUserInfo?.profile.key}
                                        type="ProvinceFinancial"
                                        address={
                                          item.ProvinceFinancial.address
                                            ?.address
                                        }
                                        postal={Number(
                                          item.ProvinceFinancial.address
                                            ?.postalCode
                                        )}
                                        accountHolder={
                                          item.ProvinceFinancial.userBankInfo
                                            ?.nameOfBankUser
                                        }
                                        card={
                                          item.ProvinceFinancial.userBankInfo
                                            ?.card
                                        }
                                        shaba={
                                          item.ProvinceFinancial.userBankInfo
                                            ?.shaba
                                        }
                                        account={
                                          item.ProvinceFinancial.userBankInfo
                                            ?.account
                                        }
                                        name_of_bank_user={
                                          item.ProvinceFinancial.userBankInfo
                                            ?.bankName
                                        }
                                      />
                                    ),
                                  })
                                );
                              }}
                            >
                              <EditIcon />
                            </IconButton>
                          </Tooltip>,
                          <Tooltip
                            key={i}
                            title={
                              item.ProvinceFinancial.trash === true
                                ? "فعالسازی کاربر"
                                : "غیر فعال کردن کاربر"
                            }
                            placement="bottom-start"
                          >
                            <FormControlLabel
                              label={
                                item.ProvinceFinancial.trash === true
                                  ? "غیرفعال"
                                  : " فعال"
                              }
                              control={
                                <Switch
                                  checked={!item.ProvinceFinancial.trash}
                                  onClick={() => {
                                    dispatch(LOADING_START());
                                    dispatch(
                                      inspectorChangeUserState({
                                        type:
                                          item.ProvinceFinancial.trash === true
                                            ? "Activate"
                                            : "Deactivate",
                                        role_data_key:
                                          item.ProvinceFinancial.key,
                                        role: "ProvinceFinancial",
                                      })
                                    ).then((r) => {
                                      dispatch(LOADING_END());
                                      window.location.reload(false);
                                    });
                                  }}
                                />
                              }
                            />
                          </Tooltip>,
                        ],
                      ]}
                    />

                    <SimpleTable
                      key={i}
                      name="اطلاعات بانکی اپراتور مالی"
                      expandable
                      columns={[
                        "نام صاحب حساب",
                        "نام بانک",
                        "شماره حساب",
                        "شماره کارت",
                        "شماره شبا",
                      ]}
                      data={[
                        [
                          item.ProvinceFinancial.userBankInfo?.nameOfBankUser,
                          item.ProvinceFinancial.userBankInfo?.bankName,
                          Number(item.ProvinceFinancial.userBankInfo?.account),
                          Number(item.ProvinceFinancial.userBankInfo?.card),
                          item.ProvinceFinancial.userBankInfo?.shaba,
                        ],
                      ]}
                    />
                  </>
                );
              } else if (Object.keys(item).includes("KillHouseVet")) {
                return (
                  <>
                    <SimpleTable
                      key={i}
                      name="اطلاعات دامپزشک کشتارگاه"
                      expandable
                      columns={[
                        "آدرس",
                        "استان",
                        "شهر",
                        "کد پستی",
                        "موبایل",
                        "ویرایش",
                        "وضعیت",
                      ]}
                      data={[
                        [
                          item.KillHouseVet.vet?.address?.address,
                          item.KillHouseVet.vet?.address?.province.name,
                          item.KillHouseVet.vet?.address?.city.name,
                          Number(item.KillHouseVet.vet?.address?.postalCode),
                          item.KillHouseVet.vet?.address?.phone,
                          <Tooltip
                            key={i}
                            title={"ویرایش کاربر"}
                            placement="bottom-start"
                          >
                            <IconButton
                              aria-label="delete"
                              color="primary"
                              className="avicultureActiveRequestsBtn"
                              onClick={() => {
                                dispatch(
                                  DRAWER({
                                    title: "ویرایش اطلاعات دامپزشک کشتارگاه",
                                    right: !(window.innerWidth <= 600),
                                    bottom: window.innerWidth <= 600,
                                    content: (
                                      <InspectorEditKillHouseVet
                                        id={item.KillHouseVet.vet?.key}
                                      />
                                    ),
                                  })
                                );
                              }}
                            >
                              <EditIcon />
                            </IconButton>
                          </Tooltip>,
                          <Tooltip
                            key={i}
                            title={
                              item.KillHouseVet.vet?.trash === true
                                ? "فعالسازی کاربر"
                                : "غیر فعال کردن کاربر"
                            }
                            placement="bottom-start"
                          >
                            <FormControlLabel
                              label={
                                item.KillHouseVet.vet?.trash === true
                                  ? "غیرفعال"
                                  : " فعال"
                              }
                              control={
                                <Switch
                                  checked={!item.KillHouseVet.vet.trash}
                                  onClick={() => {
                                    dispatch(LOADING_START());
                                    dispatch(
                                      inspectorChangeUserState({
                                        type:
                                          item.KillHouseVet.vet.trash === true
                                            ? "Activate"
                                            : "Deactivate",
                                        role_data_key: item.KillHouseVet.key,
                                        role: "KillHouseVet",
                                      })
                                    ).then((r) => {
                                      dispatch(LOADING_END());
                                      window.location.reload(false);
                                    });
                                  }}
                                />
                              }
                            />
                          </Tooltip>,
                        ],
                      ]}
                    />

                    <SimpleTable
                      key={i}
                      name="اطلاعات بانکی دامپزشک کشتارگاه"
                      expandable
                      columns={[
                        "نام صاحب حساب",
                        "نام بانک",
                        "شماره حساب",
                        "شماره کارت",
                        "شماره شبا",
                      ]}
                      data={[
                        [
                          item.KillHouseVet.vet?.userBankInfo?.nameOfBankUser,
                          item.KillHouseVet.vet?.userBankInfo?.bankName,
                          Number(item.KillHouseVet.vet?.userBankInfo?.account),
                          Number(item.KillHouseVet.vet?.userBankInfo?.card),
                          item.KillHouseVet.vet?.userBankInfo?.shaba,
                        ],
                      ]}
                    />
                  </>
                );
              } else if (Object.keys(item).includes("Driver")) {
                return (
                  <>
                    <SimpleTable
                      key={i}
                      name="اطلاعات راننده"
                      expandable
                      columns={[
                        "نام راننده",
                        "نوع خودرو",
                        "ظرفیت",
                        "کد بهداشتی",
                        "پلاک",
                        "شماره موبایل",
                        "ویرایش",
                        "وضعیت",
                      ]}
                      data={[
                        [
                          item.Driver.driverName,
                          item.Driver.typeCar,
                          item.Driver.capocity,
                          item.Driver.healthCode,
                          item.Driver.pelak,
                          item.Driver.driverMobile,

                          <Tooltip
                            key={i}
                            title={"ویرایش کاربر"}
                            placement="bottom-start"
                          >
                            <IconButton
                              aria-label="delete"
                              color="primary"
                              className="avicultureActiveRequestsBtn"
                              onClick={() => {
                                dispatch(
                                  DRAWER({
                                    title: "ویرایش اطلاعات راننده",
                                    right: !(window.innerWidth <= 600),
                                    bottom: window.innerWidth <= 600,
                                    content: (
                                      <InspectorEditDriver
                                        id={item.Driver.key}
                                        capocity={item.Driver.capocity}
                                        healthCode={item.Driver.healthCode}
                                        mobile={item.Driver.driverMobile}
                                        driverName={item.Driver.driverName}
                                        accountHolder={
                                          item.Driver.userBankInfo
                                            ?.nameOfBankUser
                                        }
                                        card={item.Driver.userBankInfo?.card}
                                        shaba={item.Driver.userBankInfo?.shaba}
                                        account={
                                          item.Driver.userBankInfo?.account
                                        }
                                        name_of_bank_user={
                                          item.Driver.userBankInfo?.bankName
                                        }
                                      />
                                    ),
                                  })
                                );
                              }}
                            >
                              <EditIcon />
                            </IconButton>
                          </Tooltip>,
                          <Tooltip
                            key={i}
                            title={
                              item.Driver?.trash === true
                                ? "فعالسازی کاربر"
                                : "غیر فعال کردن کاربر"
                            }
                            placement="bottom-start"
                          >
                            <FormControlLabel
                              label={
                                item.Driver?.trash === true
                                  ? "غیرفعال"
                                  : " فعال"
                              }
                              control={
                                <Switch
                                  checked={!item.Driver.trash}
                                  onClick={() => {
                                    dispatch(LOADING_START());
                                    dispatch(
                                      inspectorChangeUserState({
                                        type:
                                          item.Driver.trash === true
                                            ? "Activate"
                                            : "Deactivate",
                                        role_data_key: item.Driver.key,
                                        role: "Driver",
                                      })
                                    ).then((r) => {
                                      dispatch(LOADING_END());
                                      window.location.reload(false);
                                    });
                                  }}
                                />
                              }
                            />
                          </Tooltip>,
                        ],
                      ]}
                    />

                    <SimpleTable
                      key={i}
                      name="اطلاعات بانکی راننده"
                      expandable
                      columns={[
                        "نام صاحب حساب",
                        "نام بانک",
                        "شماره حساب",
                        "شماره کارت",
                        "شماره شبا",
                      ]}
                      data={[
                        [
                          item.Driver.userBankInfo?.nameOfBankUser,
                          item.Driver.userBankInfo?.bankName,
                          Number(item.Driver.userBankInfo?.account),
                          Number(item.Driver.userBankInfo?.card),
                          item.Driver.userBankInfo?.shaba,
                        ],
                      ]}
                    />
                  </>
                );
              }

              return null;
            })}
          </Grid>
        </Grid>
      </Grid>
    </>
  );
};
