"use client";
import { jsxs as c, jsx as t, Fragment as I } from "react/jsx-runtime";
import * as v from "react";
import { Icon as h } from "./icon.js";
import { Sidebar as y, SidebarHeader as z, SidebarContent as B, SidebarGroup as x, SidebarGroupLabel as A, SidebarGroupContent as N, SidebarMenu as C, SidebarMenuItem as w, SidebarMenuSub as M, SidebarMenuSubItem as E, SidebarRail as F, SidebarMenuButton as j, SidebarMenuSubButton as D } from "./sidebar.js";
function K({
  navigation: u,
  navigationFooter: G,
  headerContent: f,
  footerContent: R,
  showRail: g = !0,
  linkComponent: d,
  linkProps: m = {},
  ...k
}) {
  const [b, o] = v.useState({});
  v.useEffect(() => {
    o((e) => {
      const n = { ...e };
      return u.forEach((l) => {
        l.items.some(
          (r) => r.isActive || r.subItems && r.subItems.some((s) => s.isActive)
        ) && (n[l.title] = !0);
      }), n;
    });
  }, [u]);
  const S = (e, n, l) => {
    const i = e.subItems && e.subItems.length > 0, r = /* @__PURE__ */ c(I, { children: [
      /* @__PURE__ */ c("div", { className: "flex items-center gap-2", children: [
        e.iconName && /* @__PURE__ */ t(h, { name: e.iconName, size: "sm" }),
        /* @__PURE__ */ t("span", { children: e.title })
      ] }),
      i && /* @__PURE__ */ t("div", { className: "text-d-muted-foreground", children: n ? /* @__PURE__ */ t(h, { name: "ChevronDown", className: "h-4 w-4" }) : /* @__PURE__ */ t(h, { name: "ChevronRight", className: "h-4 w-4" }) })
    ] });
    return d ? /* @__PURE__ */ t(j, { isActive: e.isActive, children: /* @__PURE__ */ t(
      d,
      {
        href: i ? "#" : e.url,
        className: "flex w-full items-center justify-between gap-2",
        onClick: i ? l : void 0,
        ...m,
        children: r
      }
    ) }) : /* @__PURE__ */ t(j, { isActive: e.isActive, children: /* @__PURE__ */ t(
      "a",
      {
        href: i ? "#" : e.url,
        className: "flex w-full items-center justify-between gap-2",
        onClick: i ? l : void 0,
        children: r
      }
    ) });
  }, p = (e) => {
    const n = /* @__PURE__ */ c(I, { children: [
      e.iconName && /* @__PURE__ */ t(h, { name: e.iconName, size: "xs" }),
      /* @__PURE__ */ t("span", { children: e.title })
    ] });
    return d ? /* @__PURE__ */ t(D, { isActive: e.isActive, asChild: !0, children: /* @__PURE__ */ t(
      d,
      {
        href: e.url,
        className: "flex w-full items-center gap-2",
        ...m,
        children: n
      }
    ) }) : /* @__PURE__ */ t(D, { isActive: e.isActive, asChild: !0, children: /* @__PURE__ */ t("a", { href: e.url, className: "flex w-full items-center gap-2", children: n }) });
  };
  return /* @__PURE__ */ c(y, { ...k, children: [
    f && /* @__PURE__ */ t(z, { children: f }),
    /* @__PURE__ */ t(B, { children: u.map((e) => /* @__PURE__ */ c(x, { children: [
      e.title && /* @__PURE__ */ t(A, { children: e.title }),
      /* @__PURE__ */ t(N, { children: /* @__PURE__ */ t(C, { children: e.items.map((n) => {
        const l = n.subItems && n.subItems.length > 0, i = b[n.title] || !1;
        return /* @__PURE__ */ c(w, { children: [
          S(n, i, (s) => {
            l && (s.preventDefault(), o((a) => ({
              ...a,
              [n.title]: !a[n.title]
            })));
          }),
          l && i && /* @__PURE__ */ t(M, { children: n.subItems.map((s) => /* @__PURE__ */ t(E, { children: p(s) }, s.title)) })
        ] }, n.title);
      }) }) })
    ] }, e.title)) }),
    G?.map((e) => /* @__PURE__ */ c(x, { children: [
      e.title && /* @__PURE__ */ t(A, { children: e.title }),
      /* @__PURE__ */ t(N, { children: /* @__PURE__ */ t(C, { children: e.items.map((n) => {
        const l = n.subItems && n.subItems.length > 0, i = b[n.title] || !1;
        return /* @__PURE__ */ c(w, { children: [
          S(n, i, (s) => {
            l && (s.preventDefault(), o((a) => ({
              ...a,
              [n.title]: !a[n.title]
            })));
          }),
          l && i && /* @__PURE__ */ t(M, { children: n.subItems.map((s) => /* @__PURE__ */ t(E, { children: p(s) }, s.title)) })
        ] }, n.title);
      }) }) })
    ] }, e.title)),
    R,
    g && /* @__PURE__ */ t(F, {})
  ] });
}
export {
  K as AppSidebar
};
