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