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