import { SPACING } from "../data/spacing";
import { NavLink } from "../components/nav-link/NavLink";
import { useLocation } from "react-router-dom";

import LinkItem from "../components/link-item/LinkItem";
import { MdCorporateFare } from "react-icons/md";
import { BackButton } from "../components/back-button/BackButton";
import { Grid } from "../components/grid/Grid";
import {
  ROUTE_ADMINX_ROUTE_MANAGE_STEWARDS,
  ROUTE_ADMINX_ROUTE_MANAGE_STEWARDS_IN_PROVINCE,
  ROUTE_ADMINX_ROUTE_MANAGE_STEWARDS_IN_PROVINCE_LEGAL,
  ROUTE_ADMINX_ROUTE_MANAGE_STEWARDS_IN_PROVINCE_STEWARDS_REQUESTS,
  ROUTE_ADMINX_ROUTE_MANAGE_STEWARDS_IN_PROVINCE_TRUE,
  ROUTE_ADMINX_ROUTE_MANAGE_STEWARDS_OUT_PROVINCE,
  ROUTE_ADMINX_ROUTE_MANAGE_STEWARDS_OUT_PROVINCE_LEGAL,
  ROUTE_ADMINX_ROUTE_MANAGE_STEWARDS_OUT_PROVINCE_TRUE,
  ROUTE_PROVINCE_ROUTE_MANAGE_STEWARDS,
  ROUTE_PROVINCE_ROUTE_MANAGE_STEWARDS_IN_PROVINCE,
  ROUTE_PROVINCE_ROUTE_MANAGE_STEWARDS_IN_PROVINCE_LEGAL,
  ROUTE_PROVINCE_ROUTE_MANAGE_STEWARDS_IN_PROVINCE_STEWARDS_REQUESTS,
  ROUTE_PROVINCE_ROUTE_MANAGE_STEWARDS_IN_PROVINCE_TRUE,
  ROUTE_PROVINCE_ROUTE_MANAGE_STEWARDS_OUT_PROVINCE,
  ROUTE_PROVINCE_ROUTE_MANAGE_STEWARDS_OUT_PROVINCE_LEGAL,
  ROUTE_PROVINCE_ROUTE_MANAGE_STEWARDS_OUT_PROVINCE_TRUE,
  ROUTE_SLAUGHTER_MANAGE_STEWARDS,
  ROUTE_SLAUGHTER_MANAGE_STEWARDS_IN_PROVINCE,
  ROUTE_SLAUGHTER_MANAGE_STEWARDS_IN_PROVINCE_LEGAL,
  ROUTE_SLAUGHTER_MANAGE_STEWARDS_IN_PROVINCE_STEWARDS_REQUESTS,
  ROUTE_SLAUGHTER_MANAGE_STEWARDS_IN_PROVINCE_TRUE,
  ROUTE_SLAUGHTER_MANAGE_STEWARDS_OUT_PROVINCE,
  ROUTE_SLAUGHTER_MANAGE_STEWARDS_OUT_PROVINCE_LEGAL,
  ROUTE_SLAUGHTER_MANAGE_STEWARDS_OUT_PROVINCE_TRUE,
  ROUTE_SUPER_ADMIN_ROUTE_MANAGE_STEWARDS,
  ROUTE_SUPER_ADMIN_ROUTE_MANAGE_STEWARDS_IN_PROVINCE,
  ROUTE_SUPER_ADMIN_ROUTE_MANAGE_STEWARDS_IN_PROVINCE_LEGAL,
  ROUTE_SUPER_ADMIN_ROUTE_MANAGE_STEWARDS_IN_PROVINCE_STEWARDS_REQUESTS,
  ROUTE_SUPER_ADMIN_ROUTE_MANAGE_STEWARDS_IN_PROVINCE_TRUE,
  ROUTE_SUPER_ADMIN_ROUTE_MANAGE_STEWARDS_OUT_PROVINCE,
  ROUTE_SUPER_ADMIN_ROUTE_MANAGE_STEWARDS_OUT_PROVINCE_LEGAL,
  ROUTE_SUPER_ADMIN_ROUTE_MANAGE_STEWARDS_OUT_PROVINCE_TRUE,
} from "../routes/routes";
import { Box } from "@mui/material";
import { getRoleFromUrl } from "../utils/getRoleFromUrl";

const ProvinceManageStewards = () => {
  const { pathname } = useLocation();

  const isAdminX = getRoleFromUrl() === "AdminX";
  const isSuperAdmin = getRoleFromUrl() === "SuperAdmin";
  const isProvinceOperator = getRoleFromUrl() === "ProvinceOperator";
  const isSlaughter = getRoleFromUrl() === "KillHouse";

  const STEWARDS_IN_PROVINCE = isAdminX
    ? ROUTE_ADMINX_ROUTE_MANAGE_STEWARDS_IN_PROVINCE
    : isSuperAdmin
    ? ROUTE_SUPER_ADMIN_ROUTE_MANAGE_STEWARDS_IN_PROVINCE
    : isProvinceOperator
    ? ROUTE_PROVINCE_ROUTE_MANAGE_STEWARDS_IN_PROVINCE
    : isSlaughter
    ? ROUTE_SLAUGHTER_MANAGE_STEWARDS_IN_PROVINCE
    : "";

  const STEWARDS_OUT_PROVINCE = isAdminX
    ? ROUTE_ADMINX_ROUTE_MANAGE_STEWARDS_OUT_PROVINCE
    : isSuperAdmin
    ? ROUTE_SUPER_ADMIN_ROUTE_MANAGE_STEWARDS_OUT_PROVINCE
    : isProvinceOperator
    ? ROUTE_PROVINCE_ROUTE_MANAGE_STEWARDS_OUT_PROVINCE
    : isSlaughter
    ? ROUTE_SLAUGHTER_MANAGE_STEWARDS_OUT_PROVINCE
    : "";

  const STEWARDS_IN_PROVINCE_REQUESTS = isAdminX
    ? ROUTE_ADMINX_ROUTE_MANAGE_STEWARDS_IN_PROVINCE_STEWARDS_REQUESTS
    : isSuperAdmin
    ? ROUTE_SUPER_ADMIN_ROUTE_MANAGE_STEWARDS_IN_PROVINCE_STEWARDS_REQUESTS
    : isProvinceOperator
    ? ROUTE_PROVINCE_ROUTE_MANAGE_STEWARDS_IN_PROVINCE_STEWARDS_REQUESTS
    : isSlaughter
    ? ROUTE_SLAUGHTER_MANAGE_STEWARDS_IN_PROVINCE_STEWARDS_REQUESTS
    : "";

  const STEWARDS_IN_PROVINCE_TRUE = isAdminX
    ? ROUTE_ADMINX_ROUTE_MANAGE_STEWARDS_IN_PROVINCE_TRUE
    : isSuperAdmin
    ? ROUTE_SUPER_ADMIN_ROUTE_MANAGE_STEWARDS_IN_PROVINCE_TRUE
    : isProvinceOperator
    ? ROUTE_PROVINCE_ROUTE_MANAGE_STEWARDS_IN_PROVINCE_TRUE
    : isSlaughter
    ? ROUTE_SLAUGHTER_MANAGE_STEWARDS_IN_PROVINCE_TRUE
    : "";

  const STEWARDS_OUT_PROVINCE_TRUE = isAdminX
    ? ROUTE_ADMINX_ROUTE_MANAGE_STEWARDS_OUT_PROVINCE_TRUE
    : isSuperAdmin
    ? ROUTE_SUPER_ADMIN_ROUTE_MANAGE_STEWARDS_OUT_PROVINCE_TRUE
    : isProvinceOperator
    ? ROUTE_PROVINCE_ROUTE_MANAGE_STEWARDS_OUT_PROVINCE_TRUE
    : isSlaughter
    ? ROUTE_SLAUGHTER_MANAGE_STEWARDS_OUT_PROVINCE_TRUE
    : "";

  const STEWARDS_IN_PROVINCE_LEGAL = isAdminX
    ? ROUTE_ADMINX_ROUTE_MANAGE_STEWARDS_IN_PROVINCE_LEGAL
    : isSuperAdmin
    ? ROUTE_SUPER_ADMIN_ROUTE_MANAGE_STEWARDS_IN_PROVINCE_LEGAL
    : isProvinceOperator
    ? ROUTE_PROVINCE_ROUTE_MANAGE_STEWARDS_IN_PROVINCE_LEGAL
    : isSlaughter
    ? ROUTE_SLAUGHTER_MANAGE_STEWARDS_IN_PROVINCE_LEGAL
    : "";

  const STEWARDS_OUT_PROVINCE_LEGAL = isAdminX
    ? ROUTE_ADMINX_ROUTE_MANAGE_STEWARDS_OUT_PROVINCE_LEGAL
    : isSuperAdmin
    ? ROUTE_SUPER_ADMIN_ROUTE_MANAGE_STEWARDS_OUT_PROVINCE_LEGAL
    : isProvinceOperator
    ? ROUTE_PROVINCE_ROUTE_MANAGE_STEWARDS_OUT_PROVINCE_LEGAL
    : isSlaughter
    ? ROUTE_SLAUGHTER_MANAGE_STEWARDS_OUT_PROVINCE_LEGAL
    : "";

  return (
    <Box display="flex" justifyContent="center">
      <Grid
        container
        gap={SPACING.SMALL}
        p={SPACING.SMALL}
        justifyContent="center"
        xs={12}
        lg={10}
      >
        <Grid xs={12}>
          <BackButton />
        </Grid>
        {(ROUTE_ADMINX_ROUTE_MANAGE_STEWARDS === pathname ||
          ROUTE_SUPER_ADMIN_ROUTE_MANAGE_STEWARDS === pathname ||
          ROUTE_PROVINCE_ROUTE_MANAGE_STEWARDS === pathname ||
          ROUTE_SLAUGHTER_MANAGE_STEWARDS === pathname) && (
          <>
            <NavLink to={STEWARDS_IN_PROVINCE}>
              <LinkItem
                icon={<MdCorporateFare size={30} color="#244CCC" />}
                title="مباشرین داخل استان"
              />
            </NavLink>
            <NavLink to={STEWARDS_OUT_PROVINCE}>
              <LinkItem
                icon={<MdCorporateFare size={30} color="#244CCC" />}
                title="مباشرین خارج استان"
              />
            </NavLink>
          </>
        )}
        {STEWARDS_IN_PROVINCE === pathname && (
          <>
            <NavLink to={STEWARDS_IN_PROVINCE_REQUESTS}>
              <LinkItem
                icon={<MdCorporateFare size={30} color="#244CCC" />}
                title="درخواست های ثبت مباشر"
              />
            </NavLink>
            <NavLink to={STEWARDS_IN_PROVINCE_TRUE}>
              <LinkItem
                icon={<MdCorporateFare size={30} color="#244CCC" />}
                title="مباشرین حقیقی"
              />
            </NavLink>
            <NavLink to={STEWARDS_IN_PROVINCE_LEGAL}>
              <LinkItem
                icon={<MdCorporateFare size={30} color="#244CCC" />}
                title="مباشرین حقوقی"
              />
            </NavLink>
          </>
        )}

        {STEWARDS_OUT_PROVINCE === pathname && (
          <>
            <NavLink to={STEWARDS_OUT_PROVINCE_TRUE}>
              <LinkItem
                icon={<MdCorporateFare size={30} color="#244CCC" />}
                title="مباشرین حقیقی"
              />
            </NavLink>
            <NavLink to={STEWARDS_OUT_PROVINCE_LEGAL}>
              <LinkItem
                icon={<MdCorporateFare size={30} color="#244CCC" />}
                title="مباشرین حقوقی"
              />
            </NavLink>
          </>
        )}
      </Grid>
    </Box>
  );
};

export default ProvinceManageStewards;
