import { jsx as l, jsxs as S } from "react/jsx-runtime";
import { useState as M, useCallback as y, Children as C, isValidElement as u, useMemo as E } from "react";
import { useSidebarContext as N } from "../../context/sidebarContext.js";
import { SidebarMenuContext as f } from "../../context/sidebarMenuContext.js";
import P from "../sidebar-collapsed-popover/SidebarCollapsedPopover.js";
import T from "../../../tooltip/Tooltip.js";
import { c as j } from "../../../../index-BtlgVD4m.js";
const V = ({ defaultOpen: b = !1, open: s, onOpenChange: o, children: g }) => {
  const { collapsed: v } = N(), [h, x] = M(b), n = s !== void 0, i = n ? s : h, a = y(() => {
    const r = !i;
    n || x(r), o == null || o(r);
  }, [i, n, o]);
  let e = null;
  const t = [];
  C.forEach(g, (r) => {
    var m;
    u(r) && ((m = r.type) == null ? void 0 : m.displayName) === "SidebarMenuTrigger" ? e = r : t.push(r);
  });
  const d = t.length > 0, c = E(() => ({ isOpen: i, canExpand: d, toggle: a }), [i, d, a]), p = e !== null && u(e) ? e.props.label ?? "" : "";
  return v ? /* @__PURE__ */ l(f.Provider, { value: c, children: t.length > 0 ? /* @__PURE__ */ l(P, { label: p, menuChildren: t, children: /* @__PURE__ */ l("li", { children: e }) }) : /* @__PURE__ */ l("li", { children: /* @__PURE__ */ l(T, { content: p, side: "right", asChild: !0, children: e }) }) }) : /* @__PURE__ */ l(f.Provider, { value: c, children: /* @__PURE__ */ S("li", { children: [
    e,
    i && t.length > 0 && /* @__PURE__ */ l(
      "ul",
      {
        className: j(
          "flex",
          "flex-col",
          "gap-[var(--spacing-1)]",
          "border-l",
          "border-[var(--base-sidebar-border)]",
          "ml-[var(--spacing-3)]",
          "pl-[var(--spacing-2)]",
          "py-[var(--spacing-0-5)]"
        ),
        children: t
      }
    )
  ] }) });
};
V.displayName = "SidebarMenu";
export {
  V as default
};
//# sourceMappingURL=SidebarMenu.js.map
