import { Typography } from "@mui/material";
import { Grid } from "../../../../components/grid/Grid";
import { useDispatch, useSelector } from "react-redux";
import { ProvinceManageBuyReqAllowOperation } from "../province-manage-buy-req-allow-operation/ProvinceManageBuyReqAllowOperation";
import { ProvinceManageBuyReqLimitOperation } from "../province-manage-buy-req-limit-operation/ProvinceManageBuyReqLimitOperation";
import { slaughterGetPermisionState } from "../../../slaughter-house/services/slaughter-get-permision";
import { ProvinceManagementSellingSlaughterLimitation } from "../province-manage-selling-slaughter-limitaion/ProvinceManagementSellingSlaughterLimitation";
import { ProvinceManageSellingForceGovernmentalBuy } from "../../../city/components/province-manage-selling-force-governmental-buy/ProvinceManageSellingForceGovernmentalBuy";
import { getRoleFromUrl } from "../../../../utils/getRoleFromUrl";
import { ProvinceManagementMaximumLoad } from "../province-management-maximum-load/ProvinceManagementMaximumLoad";
import { ProvinceManageWarehouseLimitation } from "../province-manage-warehouse-limitation/ProvinceManageWarehouseLimitation";
import { ProvinceManageCarcassStandardLossPercent } from "../province-manage-carcass-standard-loss-percent/ProvinceManageCarcassStandardLossPercent";

export const ProvinceManageOperationModalBuyReq = ({ item, fetchdata }) => {
  const { role } = useSelector((state) => state.userSlice);
  const dispatch = useDispatch();

  const getLimitInformation = () => {
    if (role.includes("KillHouse")) {
      dispatch(slaughterGetPermisionState());
    }
  };

  return (
    <Grid container direction="column" gap={2} alignItems="flex-start" m="3">
      <Grid
        item
        container
        spacing={2}
        justifyContent="center"
        width="100%"
        m="3"
      >
        {/* <Grid item>
          <Button
            variant="contained"
            sx={{ backgroundColor: "blue", color: "white" }}
            onClick={() => {
              window.open(paymentLink, "_blank");
            }}
          >
            پرداخت بدهی
          </Button>
        </Grid>

        <Grid item>
          <Button
            variant="contained"
            sx={{ backgroundColor: "blue", color: "white" }}
            onClick={() => window.open(paymentLink, "_blank")}
          >
            لینک پرداخت
          </Button>
        </Grid> */}
      </Grid>

      <Grid
        item
        container
        alignItems="center"
        spacing={1}
        justifyContent="start"
        sx={{
          border: "1px solid #ccc",
          borderRadius: 2,
          width: "100%",
          p: 1,
        }}
      >
        <Grid item>
          <ProvinceManageBuyReqAllowOperation
            key={item.key}
            item={item}
            getLimitInformation={getLimitInformation}
          />
        </Grid>
        <Grid item>
          <Typography>مجوز ثبت درخواست</Typography>
        </Grid>
      </Grid>

      <Grid
        item
        container
        alignItems="center"
        spacing={1}
        justifyContent="start"
        sx={{
          border: "1px solid #ccc",
          borderRadius: 2,
          width: "100%",
          p: 1,
        }}
      >
        <Grid item>
          <ProvinceManageBuyReqAllowOperation
            key={`${item.key}-isDebt`}
            item={item}
            isDebt
          />
        </Grid>
        <Grid item>
          <Typography>محدودیت پنل</Typography>
        </Grid>
      </Grid>

      {/* <Grid
        item
        container
        alignItems="center"
        spacing={1}
        justifyContent="start"
        sx={{
          border: "1px solid #ccc",
          borderRadius: 2,
          width: "100%",
          p: 1,
        }}
      >
        <Grid item>
          <ProvinceManageSellingLimitaion
            key={item.key}
            item={item}
            fetchdata={fetchdata}
          />
        </Grid>
      </Grid>

      <Grid
        item
        container
        alignItems="center"
        spacing={1}
        justifyContent="start"
        sx={{
          border: "1px solid #ccc",
          borderRadius: 2,
          width: "100%",
          p: 1,
        }}
      >
        <Grid item>
          <ProvinceManageSellingMaxLimitation
            key={item.key}
            item={item}
            fetchdata={fetchdata}
          />
        </Grid>
      </Grid> */}

      <Grid
        xs={12}
        container
        alignItems="center"
        spacing={1}
        justifyContent="start"
        sx={{
          border: "1px solid #ccc",
          borderRadius: 2,
          width: "100%",
          p: 1,
        }}
      >
        <Grid item xs={12}>
          <ProvinceManageSellingForceGovernmentalBuy
            key={item.key}
            item={item}
            fetchdata={fetchdata}
          />
        </Grid>
      </Grid>

      {getRoleFromUrl() === "AdminX" && (
        <Grid
          item
          container
          alignItems="center"
          spacing={1}
          justifyContent="start"
          sx={{
            border: "1px solid #ccc",
            borderRadius: 2,
            width: "100%",
            p: 1,
          }}
        >
          <Grid item>
            <ProvinceManageBuyReqLimitOperation
              key={`limit-${item.key}`}
              item={item}
              getLimitInformation={getLimitInformation}
              fetchdata={fetchdata}
            />
          </Grid>
        </Grid>
      )}

      <Grid
        item
        container
        alignItems="center"
        spacing={1}
        justifyContent="start"
        sx={{
          border: "1px solid #ccc",
          borderRadius: 2,
          width: "100%",
          p: 1,
        }}
      >
        <Grid item>
          <ProvinceManagementSellingSlaughterLimitation
            key={item.key}
            item={item}
            fetchdata={fetchdata}
          />
        </Grid>
      </Grid>

      <Grid
        item
        container
        alignItems="center"
        spacing={1}
        justifyContent="start"
        sx={{
          border: "1px solid #ccc",
          borderRadius: 2,
          width: "100%",
          p: 1,
        }}
      >
        <Grid item>
          <ProvinceManagementMaximumLoad item={item} fetchdata={fetchdata} />
        </Grid>
      </Grid>

      <Grid
        item
        container
        alignItems="center"
        spacing={1}
        justifyContent="start"
        sx={{
          border: "1px solid #ccc",
          borderRadius: 2,
          width: "100%",
          p: 1,
        }}
      >
        <Grid item xs={12}>
          <ProvinceManageWarehouseLimitation
            item={item}
            fetchdata={fetchdata}
          />
        </Grid>
      </Grid>

      <Grid
        item
        container
        alignItems="center"
        spacing={1}
        justifyContent="start"
        sx={{
          border: "1px solid #ccc",
          borderRadius: 2,
          width: "100%",
          p: 1,
        }}
      >
        <Grid item xs={12}>
          <ProvinceManageCarcassStandardLossPercent
            item={item}
            fetchdata={fetchdata}
          />
        </Grid>
      </Grid>
    </Grid>
  );
};
