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