import { jsx as e, jsxs as t, Fragment as H } from "react/jsx-runtime";
import { useState as x, useMemo as v, useCallback as I, useEffect as J, startTransition as K, Suspense as _, lazy as j } from "react";
import { useTranslateProvider as Q } from "@/common/languageTranslator/TranslationContext";
import { m as W } from "./Features-Cshdl06N-CZ02Tt89.js";
import { showToast as X } from "@/common/toaster/toaster";
import Y from "@/hooks/useTrackEvent";
import { useTheme as Z, Card as ee, Tabs as ae, Tab as se, Button as G, Typography as L } from "@mui/material";
import u from "@mui/material/Grid2";
import { useSelector as i, useDispatch as te } from "react-redux";
import { useNavigate as re } from "react-router-dom";
import { Box as le } from "@mui/system";
import { FontAwesomeIcon as ne } from "@fortawesome/react-fontawesome";
import { faGear as ie } from "@fortawesome/free-solid-svg-icons";
import c from "prop-types";
import { getUseSkeleton as y } from "@/store/reducers/SkeletonReducer";
import { setSubMenuFeatureVal as oe, setSubMenuGroupName as me, setSubMenuId as de } from "@/store/reducers/FeatureReducer";
const N = ({ children: p, isLoading: l }) => !i(y) || !l ? p : /* @__PURE__ */ e("div", { className: "flex flex-col mt-6", children: /* @__PURE__ */ t("div", { className: "w-full justify-between flex-wrap flex flex-row", children: [
  /* @__PURE__ */ t("div", { className: "flex-wrap flex flex-row", children: [
    /* @__PURE__ */ e("div", { className: "bg-gray-300 animate-pulse rounded-sm h-[45px] w-[85px] mr-2 mb-2" }),
    /* @__PURE__ */ e("div", { className: "bg-gray-300 animate-pulse rounded-sm h-[45px] w-[85px] mr-2 mb-2" }),
    /* @__PURE__ */ e("div", { className: "bg-gray-300 animate-pulse rounded-sm h-[45px] w-[85px] mr-2 mb-2" }),
    /* @__PURE__ */ e("div", { className: "bg-gray-300 animate-pulse rounded-sm h-[45px] w-[85px] mr-2 mb-2" }),
    /* @__PURE__ */ e("div", { className: "bg-gray-300 animate-pulse rounded-sm h-[45px] w-[85px] mr-2 mb-2" })
  ] }),
  /* @__PURE__ */ t("div", { className: "flex", children: [
    /* @__PURE__ */ e("div", { className: "bg-gray-300 animate-pulse rounded-sm h-[32px] w-[120px] m-0.5" }),
    /* @__PURE__ */ e("div", { className: "bg-gray-300 animate-pulse rounded-sm h-[32px] w-[130px] m-0.5" }),
    /* @__PURE__ */ e("div", { className: "bg-gray-300 animate-pulse rounded-sm h-[32px] w-[100px] m-0.5" })
  ] })
] }) });
N.propTypes = {
  children: c.any,
  isLoading: c.any
};
c.any, c.any;
const ue = ({ children: p, isLoading: l }) => !i(y) || !l ? p : /* @__PURE__ */ t("div", { className: "w-full p-2", children: [
  /* @__PURE__ */ e("div", { className: "bg-gray-300 animate-pulse rounded-sm h-[40px] w-full mb-2" }),
  /* @__PURE__ */ e("div", { className: "bg-gray-300 animate-pulse rounded-sm h-[60px] w-full mb-2" }),
  /* @__PURE__ */ e("div", { className: "bg-gray-300 animate-pulse rounded-sm h-[280px] w-full" })
] });
ue.propTypes = {
  children: c.any,
  isLoading: c.any
};
const ce = j(() => import("./AccessRights-BMRM1u9S-D1Gc0rKI.js")), pe = j(() => import("./SubMenu-DAfZC9Xi-B0BQYLdI.js"));
function fe() {
  const p = i(y), l = Z(), b = te(), [w, P] = x([]), [n, $] = x(0), o = i((a) => {
    var s;
    return (s = a == null ? void 0 : a.FeatureReducer) == null ? void 0 : s.subMenuId;
  }), M = i(
    (a) => {
      var s;
      return (s = a == null ? void 0 : a.FeatureReducer) == null ? void 0 : s.subMenuGroupName;
    }
  ), R = i(
    (a) => {
      var s;
      return (s = a == null ? void 0 : a.FeatureReducer) == null ? void 0 : s.subMenuFeatureVal;
    }
  ), g = re(), { user: S } = i((a) => a.Authenticate), { translate: m } = Q(), [d, h] = x(!1), F = Y(), [T, V] = x({}), k = (S == null ? void 0 : S.features) || {}, r = v(
    () => Object.keys(k).filter((a) => a !== "mch"),
    [k]
  ), z = l.palette.mode === "dark" ? l.palette.divider : l.palette.grey[200], B = I((a, s) => {
    $(s);
  }, []), O = I(() => {
    F("button_click", {
      button_name: "featuremenu-add-button",
      button_type: "navigate",
      button_id: "featuremenu-add-button"
    }), g("addDynamicFeature");
  }, [g, F]);
  J(() => {
    (async () => {
      var a, s;
      if (!(!r.length || n >= r.length))
        try {
          h(!0);
          const { data: f } = await W(r[n]), A = f.sort((D, q) => {
            var C;
            return (C = D.name) == null ? void 0 : C.localeCompare(q.name);
          });
          K(() => {
            P(A), A.length > 0, h(!1);
          });
        } catch (f) {
          X({
            message: `Error : ${(s = (a = f == null ? void 0 : f.response) == null ? void 0 : a.data) == null ? void 0 : s.message}`,
            type: "error"
          }), h(!1);
        }
    })();
  }, [n, r]);
  const E = v(
    () => /* @__PURE__ */ e(_, { fallback: /* @__PURE__ */ e(N, {}), children: /* @__PURE__ */ e(
      pe,
      {
        "data-testid": "featuremenu-submenu",
        data: w,
        subMenuId: o,
        setSubMenuId: (a) => {
          b(de(a));
        },
        setSubMenuGroupName: (a) => {
          b(me(a));
        },
        setSubMenuFeatureVal: (a) => {
          b(oe(a));
        },
        type: r[n],
        isLoading: d,
        isNewAPI: T,
        subMenuGroupName: M
      }
    ) }),
    [w, o, n, d, r, T]
  ), U = v(
    () => /* @__PURE__ */ e(
      _,
      {
        fallback: /* @__PURE__ */ e("div", { className: "p-2 text-sm text-gray-500", children: "Loading Access Rights..." }),
        children: /* @__PURE__ */ e(
          ce,
          {
            "data-testid": "featuremenu-access-rights",
            subMenuId: o,
            subMenuGroupName: M,
            subMenuFeatureVal: R,
            selectedTab: r[n],
            parentLoading: d,
            onNewAPIChange: V
          }
        )
      }
    ),
    [o, d]
  );
  return /* @__PURE__ */ t(ee, { variant: "elevation", className: "p-3 mt-6 flex flex-col shadow-2xl", children: [
    /* @__PURE__ */ e(N, { isLoading: d, children: /* @__PURE__ */ t(u, { className: "w-full justify-between flex-wrap flex flex-row", children: [
      /* @__PURE__ */ e(u, { className: "flex-wrap flex flex-row", children: /* @__PURE__ */ e(
        ae,
        {
          value: n,
          onChange: B,
          variant: "scrollable",
          scrollButtons: "auto",
          children: r.map((a, s) => /* @__PURE__ */ e(
            se,
            {
              label: a.toUpperCase(),
              "data-testid": `featuremenu-button-${s}`,
              id: `feature-tab-${s}`
            },
            a
          ))
        }
      ) }),
      /* @__PURE__ */ t(u, { className: "flex gap-2 items-center ml-auto", children: [
        /* @__PURE__ */ t(
          G,
          {
            size: "small",
            className: "mb-1 ml-0.5",
            variant: "contained",
            onClick: () => g("/ui/medplat/report/all/groups"),
            sx: {
              mt: { xs: "15px", md: "0px" }
            },
            children: [
              m("Manage"),
              " ",
              m("Menu"),
              " ",
              m("Group")
            ]
          }
        ),
        /* @__PURE__ */ t(
          G,
          {
            size: "small",
            "data-testid": "featuremenu-add-button",
            className: "mb-1 ml-0.5",
            variant: "contained",
            onClick: O,
            sx: {
              mt: { xs: "15px", md: "0px" }
            },
            children: [
              m("Add"),
              " ",
              m("Feature")
            ]
          }
        )
      ] })
    ] }) }),
    /* @__PURE__ */ t(u, { container: !0, spacing: 2, className: "w-full py-3 rounded-sm", children: [
      /* @__PURE__ */ e(
        u,
        {
          size: { xs: 12, sm: 12, md: 3 },
          className: "flex",
          sx: { border: `1px solid ${z}` },
          children: E
        }
      ),
      /* @__PURE__ */ t(
        u,
        {
          size: { xs: 12, sm: 12, md: 9 },
          className: "flex flex-col",
          sx: { border: `1px solid ${z}` },
          children: [
            d && p ? /* @__PURE__ */ e("div", { className: "flex flex-col p-2", children: /* @__PURE__ */ e("div", { className: "bg-slate-200 dark:bg-slate-800 animate-pulse rounded-sm h-[30px] w-[180px]" }) }) : /* @__PURE__ */ t(le, { className: "flex items-center p-2", children: [
              /* @__PURE__ */ e(ne, { icon: ie, size: "lg", className: "mr-2" }),
              /* @__PURE__ */ e(L, { variant: "body2", className: "font-bold font-sans pt-1", children: m("Access Rights") })
            ] }),
            o && U,
            !o && /* @__PURE__ */ e(H, { children: /* @__PURE__ */ e(
              L,
              {
                variant: "body2",
                className: "p-2",
                "data-testid": "featuremenu-no-feature-selected",
                sx: {
                  textAlign: "center",
                  position: "relative",
                  top: "10%",
                  fontSize: "25px",
                  color: "grey"
                },
                children: "Please select a feature!"
              }
            ) })
          ]
        }
      )
    ] })
  ] });
}
const Ie = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  default: fe
}, Symbol.toStringTag, { value: "Module" }));
export {
  Ie as F,
  ue as S
};
//# sourceMappingURL=FeatureMenu-Ds6lFg4w-ShGx4okQ.js.map
