import { jsx, jsxs } from "react/jsx-runtime";
import default_1 from "../../node_modules/@mui/icons-material/KeyboardArrowRightOutlined.js";
import { NavLink } from "react-router-dom";
import { Tooltip } from "../Tooltip/index.js";
function parentItemClass(active, item) {
  return [
    "impact-sidebar-routes-list-item",
    item.value === active ? "route-active" : "",
    item.isDisabled ? "route-disabled" : ""
  ].filter(Boolean).join(" ");
}
function indicatorClass(isOpenSidebar, showChild, itemValue) {
  return [
    "impact-sidebar-routes-list-item-children-indicator-horizontal",
    isOpenSidebar && showChild === itemValue ? "indicator-turn-up" : ""
  ].filter(Boolean).join(" ");
}
function ParentMenu({
  isOpen,
  setIsOpen,
  active,
  item,
  showChild,
  setShowChild,
  handleRouteChange,
  isMemoryRouter
}) {
  const handleClickOnRoute = () => {
    if (item.children && item.children.length > 0) {
      if (!isOpen) {
        setIsOpen(true);
      }
      if (item.link) {
        handleRouteChange(item);
      }
      if (showChild === item.value) {
        setShowChild("");
      } else {
        setShowChild(item.value);
      }
    } else {
      handleRouteChange(item);
    }
  };
  const tooltipTitle = item.tooltip && item.tooltip.length > 0 ? item.tooltip : item.label;
  if (isOpen) {
    if (isMemoryRouter) {
      return /* @__PURE__ */ jsx(NavLink, { className: "impact-sidebar-routes-list-item-link", to: item.link ?? "/", children: /* @__PURE__ */ jsxs("div", { className: parentItemClass(active, item), onClick: handleClickOnRoute, children: [
        /* @__PURE__ */ jsx("div", { className: "impact-sidebar-routes-list-item-icon", children: item.icon }),
        /* @__PURE__ */ jsxs("div", { className: "impact-sidebar-routes-list-item-label", children: [
          /* @__PURE__ */ jsx("span", { className: "impact-sidebar-routes-list-item-label-text", children: item.label }),
          item.children && item.children.length > 0 ? /* @__PURE__ */ jsx("div", { className: indicatorClass(isOpen, showChild, item.value), role: "button", children: /* @__PURE__ */ jsx(default_1, {}) }) : null
        ] })
      ] }) });
    }
    return /* @__PURE__ */ jsxs("div", { className: parentItemClass(active, item), onClick: handleClickOnRoute, children: [
      /* @__PURE__ */ jsx("div", { className: "impact-sidebar-routes-list-item-icon", children: item.icon }),
      /* @__PURE__ */ jsxs("div", { className: "impact-sidebar-routes-list-item-label", children: [
        /* @__PURE__ */ jsx("span", { className: "impact-sidebar-routes-list-item-label-text", children: item.label }),
        item.children && item.children.length > 0 ? /* @__PURE__ */ jsx("div", { className: indicatorClass(isOpen, showChild, item.value), role: "button", children: /* @__PURE__ */ jsx(default_1, {}) }) : null
      ] })
    ] });
  }
  if (isMemoryRouter) {
    return /* @__PURE__ */ jsx(Tooltip, { orientation: "right", title: tooltipTitle, variant: "tertiary", children: /* @__PURE__ */ jsx(NavLink, { className: "impact-sidebar-routes-list-item-link", to: item.link ?? "/", children: /* @__PURE__ */ jsxs("div", { className: parentItemClass(active, item), onClick: handleClickOnRoute, children: [
      /* @__PURE__ */ jsx("div", { className: "impact-sidebar-routes-list-item-icon", children: item.icon }),
      item.children && item.children.length > 0 ? /* @__PURE__ */ jsx("div", { className: indicatorClass(isOpen, showChild, item.value), role: "button", children: /* @__PURE__ */ jsx(default_1, {}) }) : null,
      /* @__PURE__ */ jsx("div", { className: "impact-sidebar-routes-list-item-label", children: item.label })
    ] }) }) });
  }
  return /* @__PURE__ */ jsx(Tooltip, { orientation: "right", title: tooltipTitle, variant: "tertiary", children: /* @__PURE__ */ jsxs("div", { className: parentItemClass(active, item), onClick: handleClickOnRoute, children: [
    /* @__PURE__ */ jsx("div", { className: "impact-sidebar-routes-list-item-icon", children: item.icon }),
    item.children && item.children.length > 0 ? /* @__PURE__ */ jsx("div", { className: indicatorClass(isOpen, showChild, item.value), role: "button", children: /* @__PURE__ */ jsx(default_1, {}) }) : null,
    /* @__PURE__ */ jsx("div", { className: "impact-sidebar-routes-list-item-label", children: item.label })
  ] }) });
}
ParentMenu.displayName = "ParentMenu";
export {
  ParentMenu
};
