import { useLocation } from "react-router-dom";
import { VscFolderActive, VscNewFolder } from "react-icons/vsc";
import {
  FaTruckLoading,
  FaFile,
  FaFilePdf,
  FaExchangeAlt,
  FaHornbill,
} from "react-icons/fa";
import { useDispatch } from "react-redux";
import { Grid } from "../../../../components/grid/Grid";
import { SPACING } from "../../../../data/spacing";
import { LineWithText } from "../../../../components/line-with-text/LineWithText";
import { NavLink } from "../../../../components/nav-link/NavLink";
import LinkItem from "../../../../components/link-item/LinkItem";
import {
  MdCreateNewFolder,
  MdImportExport,
  MdOutlineRuleFolder,
} from "react-icons/md";
import { OPEN_MODAL } from "../../../../lib/redux/slices/appSlice";
import PorvinceGetReportOperations from "../../../province/components/province-get-report-operations/PorvinceGetReportOperations";
import {
  ROUTE_ADMINX_CITY_NEW_REQUESTS,
  ROUTE_ADMINX_STATEMENTـOFـNEED_REQUESTS,
  ROUTE_ADMINX_ALLOCATION_REQUESTS,
  ROUTE_ADMINX_PAYING_FEES_REQUESTS,
  ROUTE_ADMINX_EXPORT,
  ROUTE_ADMINX_FREE_SALES_REQUESTS,
  ROUTE_ADMINX_AUTO_ALLOCATION_REQUESTS,
  ROUTE_ADMINX_CHAINS,
  ROUTE_PROVINCEـFREE_BUY,
  ROUTE_SUPER_ADMIN_TRADING_PANEL,
  ROUTE_SUPER_ADMIN_ALLOCATED_REQUESTS,
  ROUTE_SUPER_ADMIN_ALLOCATION_REQUESTS,
  ROUTE_SUPER_ADMIN_AUTO_ALLOCATION_REQUESTS,
  ROUTE_SUPER_ADMIN_CHAINS,
  ROUTE_SUPER_ADMIN_CITY_NEW_REQUESTS,
  ROUTE_SUPER_ADMIN_EXPORT,
  ROUTE_SUPER_ADMIN_FREE_SALES_REQUESTS,
  ROUTE_SUPER_ADMIN_ISSUANCE_OF_LETTER,
  ROUTE_SUPER_ADMIN_PAYING_FEES_REQUESTS,
  ROUTE_SUPER_ADMIN_STATEMENTـOFـNEED_REQUESTS,
  ROUTE_SUPER_ADMIN_TRANSACTIONS,
  ROUTE_ADMINX_TRANSACTIONS,
  ROUTE_ADMINX_ALLOCATED_REQUESTS,
  ROUTE_ADMINX_ISSUANCE_OF_LETTER,
} from "../../../../routes/routes";
import { getRoleFromUrl } from "../../../../utils/getRoleFromUrl";

export const SuperAdminRequestsOperations = () => {
  const { pathname } = useLocation();
  const dispatch = useDispatch();

  const getRoleBasedRoute = (superAdminRoute, adminxRoute) => {
    return getRoleFromUrl() === "SuperAdmin" ? superAdminRoute : adminxRoute;
  };

  return (
    <Grid
      container
      gap={SPACING.SMALL}
      p={SPACING.SMALL}
      direction={{ xs: "column", md: "row" }}
      justifyContent="center"
      style={{ placeContent: "baseline" }}
    >
      <Grid container direction="column" style={{ width: "100%" }}>
        <Grid>
          <LineWithText text="مدیریت درخواست ها" />
        </Grid>
        <Grid container justifyContent="center" gap={SPACING.SMALL}>
          <NavLink
            to={getRoleBasedRoute(
              ROUTE_SUPER_ADMIN_CITY_NEW_REQUESTS,
              ROUTE_ADMINX_CITY_NEW_REQUESTS
            )}
            active={
              pathname === ROUTE_SUPER_ADMIN_CITY_NEW_REQUESTS ? "true" : null
            }
          >
            <LinkItem
              icon={<VscNewFolder size={30} color="#244CCC" />}
              title="درخواست های کشتار"
              description="درخواست های کشتار مرغدار در انتظار بررسی"
            />
          </NavLink>
          <NavLink
            to={getRoleBasedRoute(
              ROUTE_SUPER_ADMIN_STATEMENTـOFـNEED_REQUESTS,
              ROUTE_ADMINX_STATEMENTـOFـNEED_REQUESTS
            )}
            active={
              pathname === ROUTE_SUPER_ADMIN_STATEMENTـOFـNEED_REQUESTS
                ? "true"
                : null
            }
          >
            <LinkItem
              icon={<MdOutlineRuleFolder size={30} color="#244CCC" />}
              title="اعلام نیاز خریداران"
              description="درخواست های کشتار در انتظار بررسی"
            />
          </NavLink>
          <NavLink
            to={getRoleBasedRoute(
              ROUTE_SUPER_ADMIN_ALLOCATION_REQUESTS,
              ROUTE_ADMINX_ALLOCATION_REQUESTS
            )}
            active={
              pathname === ROUTE_SUPER_ADMIN_ALLOCATION_REQUESTS ? "true" : null
            }
          >
            <LinkItem
              icon={<VscFolderActive size={30} color="#244CCC" />}
              title="تخصیصات"
              description="مشاهده و تخصیص درخواست ها"
            />
          </NavLink>
          <NavLink
            to={getRoleBasedRoute(
              ROUTE_SUPER_ADMIN_PAYING_FEES_REQUESTS,
              ROUTE_ADMINX_PAYING_FEES_REQUESTS
            )}
            active={
              pathname === ROUTE_SUPER_ADMIN_PAYING_FEES_REQUESTS
                ? "true"
                : null
            }
          >
            <LinkItem
              icon={<FaTruckLoading size={30} color="#244CCC" />}
              title="تعرفه  ها"
            />
          </NavLink>
        </Grid>
      </Grid>

      <Grid container direction="column" style={{ width: "100%" }}>
        <Grid>
          <LineWithText text="ویژه" />
        </Grid>
        <Grid container justifyContent="center" gap={SPACING.SMALL}>
          <NavLink
            to={getRoleBasedRoute(
              ROUTE_PROVINCEـFREE_BUY,
              ROUTE_PROVINCEـFREE_BUY
            )}
            active={pathname === ROUTE_PROVINCEـFREE_BUY ? "true" : null}
          >
            <LinkItem
              icon={<MdCreateNewFolder size={30} color="#244CCC" />}
              title="خرید مستقیم"
            />
          </NavLink>
          <NavLink
            to={getRoleBasedRoute(
              ROUTE_SUPER_ADMIN_TRADING_PANEL,
              ROUTE_SUPER_ADMIN_TRADING_PANEL
            )}
            active={
              pathname === ROUTE_SUPER_ADMIN_TRADING_PANEL ? "true" : null
            }
          >
            <LinkItem
              icon={<MdCreateNewFolder size={30} color="#244CCC" />}
              title="پنل معاملات"
            />
          </NavLink>
          <NavLink
            to={getRoleBasedRoute(
              ROUTE_SUPER_ADMIN_EXPORT,
              ROUTE_ADMINX_EXPORT
            )}
            active={pathname === ROUTE_SUPER_ADMIN_EXPORT ? "true" : null}
          >
            <LinkItem
              icon={<MdImportExport size={30} color="#244CCC" />}
              title="صادرات"
            />
          </NavLink>
          <NavLink
            to={getRoleBasedRoute(
              ROUTE_SUPER_ADMIN_FREE_SALES_REQUESTS,
              ROUTE_ADMINX_FREE_SALES_REQUESTS
            )}
          >
            <LinkItem
              icon={<VscFolderActive size={30} color="#244CCC" />}
              title="فروش خارج از استان"
            />
          </NavLink>
          <NavLink
            to={getRoleBasedRoute(
              ROUTE_SUPER_ADMIN_AUTO_ALLOCATION_REQUESTS,
              ROUTE_ADMINX_AUTO_ALLOCATION_REQUESTS
            )}
            active={
              pathname === ROUTE_SUPER_ADMIN_AUTO_ALLOCATION_REQUESTS
                ? "true"
                : null
            }
          >
            <LinkItem
              icon={<VscFolderActive size={30} color="#244CCC" />}
              title="تخصیصات خودکار"
            />
          </NavLink>
          <NavLink
            to={getRoleBasedRoute(
              ROUTE_SUPER_ADMIN_CHAINS,
              ROUTE_ADMINX_CHAINS
            )}
            active={pathname === ROUTE_SUPER_ADMIN_CHAINS ? "true" : null}
          >
            <LinkItem
              icon={<FaHornbill size={30} color="#244CCC" />}
              title="زنجیره ها"
            />
          </NavLink>
        </Grid>
      </Grid>

      <Grid container direction="column" style={{ width: "100%" }}>
        <Grid>
          <LineWithText text="نظارت درخواست ها" />
        </Grid>
        <Grid
          container
          justifyContent="center"
          placeContent="baseline"
          gap={SPACING.SMALL}
        >
          <NavLink
            to={getRoleBasedRoute(
              ROUTE_SUPER_ADMIN_ALLOCATED_REQUESTS,
              ROUTE_ADMINX_ALLOCATED_REQUESTS
            )}
            active={
              pathname === ROUTE_SUPER_ADMIN_ALLOCATED_REQUESTS ? "true" : null
            }
          >
            <LinkItem
              icon={<VscFolderActive size={30} color="#244CCC" />}
              title="مدیریت تخصیصات"
            />
          </NavLink>
          <NavLink
            to={getRoleBasedRoute(
              ROUTE_SUPER_ADMIN_ISSUANCE_OF_LETTER,
              ROUTE_ADMINX_ISSUANCE_OF_LETTER
            )}
            active={
              pathname === ROUTE_SUPER_ADMIN_ISSUANCE_OF_LETTER ? "true" : null
            }
          >
            <LinkItem
              icon={
                <FaFile className="svg-icon-color" color="#244CCC" size={30} />
              }
              title="صدور نامه"
              description="ارسال نامه سیستمی"
            />
          </NavLink>

          <NavLink
            onClick={() =>
              dispatch(
                OPEN_MODAL({
                  title: "اطلاعات گزارش",
                  content: <PorvinceGetReportOperations />,
                })
              )
            }
          >
            <LinkItem
              icon={
                <FaFilePdf
                  className="svg-icon-color"
                  color="#244CCC"
                  size={30}
                />
              }
              title="گزارش روزانه"
              description="گزارش روزانه"
            />
          </NavLink>

          <NavLink
            to={getRoleBasedRoute(
              ROUTE_SUPER_ADMIN_TRANSACTIONS,
              ROUTE_ADMINX_TRANSACTIONS
            )}
            active={pathname === ROUTE_SUPER_ADMIN_TRANSACTIONS ? "true" : null}
          >
            <LinkItem
              icon={
                <FaExchangeAlt
                  size={30}
                  style={{ color: "#4285F4" }}
                  color="#244CCC"
                />
              }
              title="تراکنش ها"
            />
          </NavLink>
        </Grid>
      </Grid>
    </Grid>
  );
};
