import { jsxs as d, Fragment as K, jsx as a } from "react/jsx-runtime";
import { useState as o, Suspense as T, lazy as M } from "react";
import { useSelector as W } from "react-redux";
import "@/assets/scss/scrollBar.scss";
import { useTranslateProvider as X } from "@/common/languageTranslator/TranslationContext";
import { useTheme as Z, Typography as p, TextField as _, TableContainer as ee, Table as ae, TableBody as re, TableRow as te, TableCell as oe, List as k, ListItem as I, darken as ne } from "@mui/material";
import s from "@mui/material/Grid2";
import r from "prop-types";
import { useNavigate as se } from "react-router-dom";
import { FontAwesomeIcon as h } from "@fortawesome/react-fontawesome";
import { faArrowsRotate as le, faPen as ie, faFloppyDisk as ce } from "@fortawesome/free-solid-svg-icons";
import { S as de } from "./FeatureMenu-Ds6lFg4w.js";
const ue = M(() => import("./FlywayQuery-Cx2sly6g.js")), me = M(() => import("./ServerSyncModal-D_oFpv3C.js"));
function pe({
  data: y,
  subMenuId: i,
  setSubMenuId: $,
  setSubMenuGroupName: L,
  setSubMenuFeatureVal: A,
  type: f,
  isLoading: D,
  isNewAPI: P,
  subMenuGroupName: z
}) {
  const [b, q] = o(""), [S, g] = o(!1), [x, N] = o(null), [v, B] = o(""), [C, w] = o(!1), [R, j] = o(), [G, O] = o({}), [Q, E] = o(""), u = Z().palette.divider, c = y.filter(
    (e) => e.name.toLowerCase().includes(b.toLowerCase())
  ), { translate: F } = X(), { user: n } = W((e) => e.Authenticate), H = (n == null ? void 0 : n.roleCode) === "argusadmin" || (n == null ? void 0 : n.roleCode) === "medplatadmin", U = se(), V = (e, t, l) => {
    const m = t ? "DYNAMIC" : "STATIC", J = `addDynamicFeature?${new URLSearchParams({
      featureId: e,
      featureType: l,
      subMenuGroupName: z,
      staticOrDynamic: m
    }).toString()}`;
    U(J, { state: { isNew: P } });
  }, Y = (e, t, l) => {
    j(e), E(t), O(l), w(!0);
  };
  return /* @__PURE__ */ d(K, { children: [
    /* @__PURE__ */ a(de, { isLoading: D, children: /* @__PURE__ */ d(s, { container: !0, className: "flex flex-col w-full", children: [
      /* @__PURE__ */ a(s, { className: "p-2.5 flex-0", sx: { borderBottom: `1px solid ${u}` }, children: /* @__PURE__ */ a(p, { variant: "body2", className: "pl-1.5 font-bold pt-0.5", children: F("List of Sub Menus") }) }),
      /* @__PURE__ */ a(s, { className: "px-2 py-1 flex-0", sx: { borderBottom: `1px solid ${u}` }, children: /* @__PURE__ */ a(
        _,
        {
          placeholder: "Search Features",
          variant: "outlined",
          size: "small",
          value: b,
          onChange: (e) => q(e.target.value),
          sx: {
            width: "100%",
            backgroundColor: (e) => e.palette.background.paper
          },
          "data-testid": "submenu-search-input"
        }
      ) }),
      /* @__PURE__ */ a(s, { width: "100%", className: "flex-1  ", children: /* @__PURE__ */ a(
        ee,
        {
          className: "",
          style: { maxHeight: "calc(100vh - 300px)" },
          children: /* @__PURE__ */ a(ae, { children: /* @__PURE__ */ a(re, { children: /* @__PURE__ */ a(
            te,
            {
              sx: {
                backgroundColor: (e) => e.palette.background.main
              },
              children: /* @__PURE__ */ a(oe, { className: "p-0 h-full align-top", children: /* @__PURE__ */ a(s, { children: c.length ? /* @__PURE__ */ a(k, { className: "p-0 m-0", children: c == null ? void 0 : c.map(
                (e, t, l) => /* @__PURE__ */ d(
                  I,
                  {
                    className: "flex justify-between px-4 py-2 transition-colors duration-300",
                    onMouseEnter: () => N(t),
                    onMouseLeave: () => N(null),
                    onClick: () => {
                      $(e.id), L(e.groupName), A(e.isNewFeature);
                    },
                    "data-testid": `submenu-list-item-${e.id}`,
                    sx: {
                      borderBottom: t === l.length - 1 ? "none" : `1px solid ${u}`,
                      backgroundColor: (m) => i === e.id ? ne(
                        m.palette.background.default,
                        0.1
                      ) : "inherit"
                    },
                    children: [
                      /* @__PURE__ */ a(
                        p,
                        {
                          variant: "body2",
                          className: `m-0 ${i === e.id || x === t ? "font-bold" : "font-normal"} ${x === t ? "cursor-pointer" : "cursor-default"}`,
                          children: e.name
                        }
                      ),
                      e.isDynamicReport !== !0 && H && /* @__PURE__ */ d(s, { className: "flex flex-row", children: [
                        e.isDynamicFeature && /* @__PURE__ */ a(
                          h,
                          {
                            size: "lg",
                            icon: le,
                            rotation: 90,
                            onClick: () => Y(
                              e.id,
                              e.navigationState,
                              e
                            ),
                            className: "mr-2 text-[var(--color-primary)]"
                          }
                        ),
                        /* @__PURE__ */ a(
                          "button",
                          {
                            onClick: () => V(
                              e.id,
                              e.isDynamicFeature,
                              f
                            ),
                            disabled: e.id !== i,
                            className: `mr-2 ${e.id !== i ? "text-gray-400 cursor-not-allowed" : "text-[var(--color-primary)]"}`,
                            children: /* @__PURE__ */ a(
                              h,
                              {
                                size: "lg",
                                icon: ie,
                                "data-testid": `submenu-edit-button-${e.id}`
                              }
                            )
                          }
                        ),
                        /* @__PURE__ */ a(
                          h,
                          {
                            icon: ce,
                            size: "lg",
                            onClick: () => {
                              g(!0), B(e.id);
                            },
                            "data-testid": `submenu-save-button-${e.id}`,
                            className: "mr-1 text-[var(--color-primary)] cursor-pointer"
                          }
                        )
                      ] })
                    ]
                  },
                  e == null ? void 0 : e.id
                )
              ) }) : /* @__PURE__ */ a(k, { className: "p-0 m-0", children: /* @__PURE__ */ a(I, { children: /* @__PURE__ */ a(p, { variant: "body2", className: " m-0", children: F("No features for search query") }) }) }) }) })
            }
          ) }) })
        }
      ) })
    ] }) }),
    S === !0 && /* @__PURE__ */ a(T, { children: /* @__PURE__ */ a(
      ue,
      {
        "data-testid": "submenu-flywayquery",
        open: S,
        data: v ? y.find((e) => e.id === v) : {},
        type: f,
        handleClose: () => g(!1)
      }
    ) }),
    /* @__PURE__ */ a(T, { children: C && /* @__PURE__ */ a(
      me,
      {
        id: R,
        selectedFeature: G,
        navigationState: Q,
        openServerSyncModal: C,
        openModalFunc: w
      }
    ) })
  ] });
}
pe.propTypes = {
  data: r.any,
  subMenuId: r.any,
  setSubMenuId: r.any,
  setSubMenuGroupName: r.any,
  setSubMenuFeatureVal: r.any,
  type: r.any,
  isLoading: r.any,
  isNewAPI: r.any,
  subMenuGroupName: r.any
};
export {
  pe as default
};
//# sourceMappingURL=SubMenu-DAfZC9Xi.js.map
