"use client";
import { jsx, jsxs } from "react/jsx-runtime";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { cn } from "../../lib/utils/index.js";
import { ChevronRight, FileText, Folder, Shield } from "lucide-react";
import { useState } from "react";
function SuperadminDocsSidebar({ sections }) {
  const pathname = usePathname();
  const getActiveSection = () => {
    const parts = pathname.split("/").filter(Boolean);
    if (parts[0] === "superadmin" && parts[1] === "docs" && parts.length >= 3) {
      return parts[2];
    }
    return null;
  };
  const activeSection = getActiveSection();
  const [expandedSections, setExpandedSections] = useState(() => {
    return activeSection ? /* @__PURE__ */ new Set([activeSection]) : /* @__PURE__ */ new Set();
  });
  const toggleSection = (slug) => {
    const newExpanded = new Set(expandedSections);
    if (newExpanded.has(slug)) {
      newExpanded.delete(slug);
    } else {
      newExpanded.add(slug);
    }
    setExpandedSections(newExpanded);
  };
  const handleKeyDown = (e, slug) => {
    if (e.key === "Enter" || e.key === " ") {
      e.preventDefault();
      toggleSection(slug);
    }
  };
  return /* @__PURE__ */ jsxs(
    "nav",
    {
      className: "h-full overflow-y-auto p-4",
      "aria-label": "Admin documentation navigation",
      "data-cy": "superadmin-docs-sidebar",
      children: [
        /* @__PURE__ */ jsxs("div", { className: "mb-6", children: [
          /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 mb-2", children: [
            /* @__PURE__ */ jsx(Shield, { className: "h-5 w-5 text-red-600" }),
            /* @__PURE__ */ jsx("h2", { className: "text-lg font-semibold", children: "Admin Docs" })
          ] }),
          /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "Documentation for administrators" })
        ] }),
        /* @__PURE__ */ jsx("div", { className: "space-y-2", children: sections.map((section) => {
          const isExpanded = expandedSections.has(section.slug);
          const isActive = activeSection === section.slug;
          return /* @__PURE__ */ jsxs("div", { className: "space-y-1", children: [
            /* @__PURE__ */ jsxs(
              "button",
              {
                onClick: () => toggleSection(section.slug),
                onKeyDown: (e) => handleKeyDown(e, section.slug),
                className: cn(
                  "flex items-center w-full text-left px-2 py-1.5 rounded-md transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
                  isActive ? "bg-red-500/10 text-red-700 dark:text-red-400 font-semibold hover:bg-red-500/15" : "hover:bg-accent"
                ),
                "aria-expanded": isExpanded,
                "aria-controls": `section-${section.slug}`,
                "data-cy": `superadmin-docs-section-${section.slug}`,
                children: [
                  /* @__PURE__ */ jsx(
                    ChevronRight,
                    {
                      className: cn(
                        "h-4 w-4 mr-1 transition-transform",
                        isExpanded && "rotate-90"
                      ),
                      "aria-hidden": "true"
                    }
                  ),
                  /* @__PURE__ */ jsx(Folder, { className: cn(
                    "h-4 w-4 mr-2",
                    isActive ? "text-red-600 dark:text-red-400" : "text-muted-foreground"
                  ), "aria-hidden": "true" }),
                  /* @__PURE__ */ jsx("span", { className: "text-sm font-medium flex-1", children: section.title })
                ]
              }
            ),
            isExpanded && /* @__PURE__ */ jsx(
              "div",
              {
                className: "ml-6 space-y-0.5",
                id: `section-${section.slug}`,
                "data-cy": `superadmin-docs-pages-${section.slug}`,
                children: section.pages.map((page) => {
                  const href = `/superadmin/docs/${section.slug}/${page.slug}`;
                  const isPageActive = pathname === href;
                  return /* @__PURE__ */ jsxs(
                    Link,
                    {
                      href,
                      className: cn(
                        "flex items-center px-2 py-1.5 rounded-md text-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
                        isPageActive ? "bg-accent text-accent-foreground font-medium" : "hover:bg-accent/50"
                      ),
                      "aria-current": isPageActive ? "page" : void 0,
                      "data-cy": `superadmin-docs-page-${page.slug}`,
                      children: [
                        /* @__PURE__ */ jsx(FileText, { className: "h-3.5 w-3.5 mr-2", "aria-hidden": "true" }),
                        /* @__PURE__ */ jsx("span", { children: page.title })
                      ]
                    },
                    page.slug
                  );
                })
              }
            )
          ] }, section.slug);
        }) })
      ]
    }
  );
}
export {
  SuperadminDocsSidebar
};
