import { jsx as e, jsxs as C } from "@emotion/react/jsx-runtime";
import { Box as S, Grid as b } from "@mui/material";
import { useState as x } from "react";
import z from "../../../../hook/topBarContext/index.js";
import { ArrowIcon as E } from "./subcomponents/ArrowIcon/index.js";
import A from "clsx";
import { isActive as R } from "../../../../utils/isActive/index.js";
import { TopBarClasses as _ } from "../../../../classes/index.js";
import { TEST_PROP_ID as s } from "../../../../../../../test/constants_no_mock.js";
import { getNameDataTestId as d } from "../../../../../../../test/getNameDataTestId.js";
import { componentName as m } from "../../../../classes/constants.js";
import { Accordion as w } from "../../../../../../extended/mui/Accordion/Accordion.js";
import { Button as i } from "../../../../../../extended/mui/Button/Button.js";
import { Popover as B } from "../../../../../../extended/mui/Popover/Popover.js";
const U = (O) => {
  const { classes: l, dataTestId: a } = z(), { itemRootData: r } = O, { title: p, children: u, module_id: t } = r, [T, h] = x(null), [c, f] = x(null), v = (n, o) => {
    h(n.currentTarget), f(o);
  }, g = () => {
    h(null), f(null);
  }, I = (n) => n.map((o, P) => /* @__PURE__ */ e(b, { item: !0, xs: 12, children: o.children ? o.children && o.children.length > 0 && /* @__PURE__ */ e(w, { label: o.title, children: I(o.children) }) : /* @__PURE__ */ e(
    "div",
    {
      className: A(
        l.ItemSelect,
        o.path === window.location.pathname ? _.IsActive : null
      ),
      ...process.env.NODE_ENV !== "production" ? { [s]: d(m, "ItemSelect", a) } : {},
      children: /* @__PURE__ */ e(i, { variant: "text", href: o.path, fullWidth: !0, label: o.title })
    }
  ) }, P)), N = () => /* @__PURE__ */ e(
    B,
    {
      elevation: 3,
      id: t,
      open: c === r.module_id,
      anchorEl: T,
      onClose: g,
      anchorOrigin: {
        vertical: "bottom",
        horizontal: "center"
      },
      transformOrigin: {
        vertical: "top",
        horizontal: "center"
      },
      arrowType: "top-center",
      children: /* @__PURE__ */ e(b, { container: !0, spacing: 0.5, children: u && u.length > 0 && I(u) })
    }
  ), D = () => r.children && r.path ? /* @__PURE__ */ C(
    "div",
    {
      className: l.ContainerAccordionCase1,
      ...process.env.NODE_ENV !== "production" ? {
        [s]: d(
          m,
          "ContainerAccordionCase1",
          a
        )
      } : {},
      children: [
        /* @__PURE__ */ e(i, { size: "medium", variant: "text", href: r.path, label: p }),
        /* @__PURE__ */ e(
          i,
          {
            variant: "text",
            id: t,
            onClick: (n) => v(n, t),
            endIcon: /* @__PURE__ */ e(E, { openState: c === t }),
            label: ""
          }
        ),
        N()
      ]
    }
  ) : r.children ? /* @__PURE__ */ C(
    "div",
    {
      className: l.ContainerAccordion,
      ...process.env.NODE_ENV !== "production" ? { [s]: d(m, "ContainerAccordion", a) } : {},
      children: [
        /* @__PURE__ */ e(
          i,
          {
            "aria-describedby": t,
            label: p,
            variant: "text",
            size: "medium",
            onClick: (n) => v(n, r.module_id),
            endIcon: /* @__PURE__ */ e(E, { openState: c === t })
          }
        ),
        N()
      ]
    }
  ) : r.path ? /* @__PURE__ */ e(i, { variant: "text", size: "medium", href: r.path, "aria-describedby": t, label: p }) : null;
  return /* @__PURE__ */ e(
    S,
    {
      className: A(
        l.ItemRoot,
        R(r) || c === r.module_id ? _.IsActive : null
      ),
      ...process.env.NODE_ENV !== "production" ? { [s]: d(m, "ItemRoot", a) } : {},
      children: D()
    }
  );
};
export {
  U as NavItemRoot
};
