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