"use client";
import { jsx, jsxs } from "react/jsx-runtime";
import Link from "next/link";
import { usePathname } from "next/navigation";
import {
  LayoutDashboard,
  Users,
  Users2,
  BarChart3,
  Settings,
  Shield,
  ArrowLeft,
  ChevronLeft,
  ChevronRight,
  CreditCard,
  FileText,
  Puzzle,
  Star,
  Bell,
  Globe,
  Layers,
  GitBranch,
  LayoutGrid,
  Tag,
  Code
} from "lucide-react";
import { cn } from "../../../lib/utils/index.js";
import { Button } from "../../ui/button.js";
import { sel } from "../../../lib/test/index.js";
import { useState } from "react";
import { getPluginNavItems } from "@nextsparkjs/registries/plugin-registry.client";
const PLUGIN_ICON_MAP = {
  Puzzle,
  Settings,
  Star,
  Code,
  LayoutGrid,
  Bell,
  Globe,
  Layers,
  GitBranch,
  Tag
};
function SuperadminSidebar({ pluginItems: pluginItemsProp } = {}) {
  const pathname = usePathname();
  const [isCollapsed, setIsCollapsed] = useState(false);
  const pluginItems = pluginItemsProp ?? getPluginNavItems("superadmin");
  const sidebarItems = [
    {
      title: "Dashboard",
      href: "/superadmin",
      icon: LayoutDashboard,
      description: "Main control panel overview",
      selectorKey: "dashboard"
    },
    {
      title: "Users",
      href: "/superadmin/users",
      icon: Users,
      description: "Manage all users and superadmins",
      selectorKey: "users"
    },
    {
      title: "Teams",
      href: "/superadmin/teams",
      icon: Users2,
      description: "View all teams and members",
      selectorKey: "teams"
    },
    {
      title: "Team Roles",
      href: "/superadmin/team-roles",
      icon: Shield,
      description: "View roles & permissions matrix",
      selectorKey: "teamRoles"
    },
    {
      title: "Documentation",
      href: "/superadmin/docs",
      icon: FileText,
      description: "Admin guides and references",
      selectorKey: "docs"
    },
    {
      title: "Subscriptions",
      href: "/superadmin/subscriptions",
      icon: CreditCard,
      description: "Billing and subscription management",
      selectorKey: "subscriptions"
    },
    {
      title: "Analytics",
      href: "/superadmin/analytics",
      icon: BarChart3,
      description: "Platform statistics",
      disabled: true,
      selectorKey: "analytics"
    },
    {
      title: "System Config",
      href: "/superadmin/config",
      icon: Settings,
      description: "Application settings",
      disabled: true,
      selectorKey: "config"
    }
  ];
  return /* @__PURE__ */ jsxs("div", { className: cn(
    "flex flex-col h-screen bg-card border-r border-border transition-all duration-300",
    isCollapsed ? "w-16" : "w-64"
  ), children: [
    /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between p-4 border-b border-border", children: [
      !isCollapsed && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
        /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center w-8 h-8 bg-red-100 rounded-lg", children: /* @__PURE__ */ jsx(Shield, { className: "h-5 w-5 text-red-600" }) }),
        /* @__PURE__ */ jsxs("div", { children: [
          /* @__PURE__ */ jsx("h2", { className: "text-lg font-bold text-red-600", children: "Super Admin" }),
          /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: "System Panel" })
        ] })
      ] }),
      /* @__PURE__ */ jsx(
        Button,
        {
          variant: "ghost",
          size: "sm",
          onClick: () => setIsCollapsed(!isCollapsed),
          "aria-label": isCollapsed ? "Expand sidebar" : "Collapse sidebar",
          className: "ml-auto",
          children: isCollapsed ? /* @__PURE__ */ jsx(ChevronRight, { className: "h-4 w-4" }) : /* @__PURE__ */ jsx(ChevronLeft, { className: "h-4 w-4" })
        }
      )
    ] }),
    /* @__PURE__ */ jsx("div", { className: "flex-1 p-3 space-y-2", children: sidebarItems.map((item) => {
      const IconComponent = item.icon;
      const isActive = pathname === item.href;
      if (item.disabled) {
        return /* @__PURE__ */ jsxs(
          "div",
          {
            className: cn(
              "flex items-center gap-3 px-3 py-2 rounded-lg text-muted-foreground cursor-not-allowed opacity-60",
              isCollapsed && "justify-center"
            ),
            title: isCollapsed ? `${item.title} (Coming Soon)` : item.description,
            children: [
              /* @__PURE__ */ jsx(IconComponent, { className: "h-5 w-5 flex-shrink-0" }),
              !isCollapsed && /* @__PURE__ */ jsxs("div", { className: "flex-1", children: [
                /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
                  /* @__PURE__ */ jsx("span", { className: "text-sm font-medium", children: item.title }),
                  /* @__PURE__ */ jsx("span", { className: "text-xs bg-muted text-muted-foreground px-2 py-0.5 rounded", children: "Soon" })
                ] }),
                item.description && /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: item.description })
              ] })
            ]
          },
          item.title
        );
      }
      return /* @__PURE__ */ jsxs(
        Link,
        {
          href: item.href,
          "data-cy": item.selectorKey ? sel(`superadmin.sidebar.nav.${item.selectorKey}`) : void 0,
          className: cn(
            "flex items-center gap-3 px-3 py-2 rounded-lg transition-colors",
            "hover:bg-accent hover:text-accent-foreground",
            isActive ? "bg-primary text-primary-foreground" : "text-foreground",
            isCollapsed && "justify-center"
          ),
          title: isCollapsed ? item.title : item.description,
          children: [
            /* @__PURE__ */ jsx(IconComponent, { className: "h-5 w-5 flex-shrink-0" }),
            !isCollapsed && /* @__PURE__ */ jsxs("div", { className: "flex-1", children: [
              /* @__PURE__ */ jsx("div", { className: "text-sm font-medium", children: item.title }),
              item.description && /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: item.description })
            ] })
          ]
        },
        item.title
      );
    }) }),
    pluginItems.length > 0 && /* @__PURE__ */ jsxs("div", { className: "px-3 pb-2 space-y-1", children: [
      !isCollapsed && /* @__PURE__ */ jsx("p", { className: "px-3 py-1 text-xs font-semibold text-muted-foreground uppercase tracking-wider", children: "Plugins" }),
      isCollapsed && /* @__PURE__ */ jsx("div", { className: "my-1 border-t border-border" }),
      pluginItems.map((item) => {
        const IconComponent = PLUGIN_ICON_MAP[item.icon ?? ""] ?? Puzzle;
        const isActive = pathname === item.href || pathname.startsWith(item.href + "/");
        return /* @__PURE__ */ jsxs(
          Link,
          {
            href: item.href,
            "data-cy": `superadmin-plugin-nav-${item.href.split("/").pop()}`,
            className: cn(
              "flex items-center gap-3 px-3 py-2 rounded-lg transition-colors",
              "hover:bg-accent hover:text-accent-foreground",
              isActive ? "bg-primary text-primary-foreground" : "text-foreground",
              isCollapsed && "justify-center"
            ),
            title: isCollapsed ? item.label : item.description,
            children: [
              /* @__PURE__ */ jsx(IconComponent, { className: "h-5 w-5 flex-shrink-0" }),
              !isCollapsed && /* @__PURE__ */ jsxs("div", { className: "flex-1", children: [
                /* @__PURE__ */ jsx("div", { className: "text-sm font-medium", children: item.label }),
                item.description && /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: item.description })
              ] })
            ]
          },
          item.href
        );
      })
    ] }),
    /* @__PURE__ */ jsxs("div", { className: "p-3 border-t border-border", children: [
      /* @__PURE__ */ jsxs(
        Link,
        {
          href: "/dashboard",
          className: cn(
            "flex items-center gap-3 px-3 py-2 rounded-lg transition-colors",
            "hover:bg-accent hover:text-accent-foreground text-muted-foreground",
            isCollapsed && "justify-center"
          ),
          title: isCollapsed ? "Exit Super Admin" : "Return to main dashboard",
          "aria-label": "Exit Super Admin and return to main dashboard",
          "data-cy": sel("superadmin.sidebar.exitButton"),
          children: [
            /* @__PURE__ */ jsx(ArrowLeft, { className: "h-5 w-5 flex-shrink-0" }),
            !isCollapsed && /* @__PURE__ */ jsxs("div", { className: "flex-1", children: [
              /* @__PURE__ */ jsx("div", { className: "text-sm font-medium", children: "Exit Super Admin" }),
              /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: "Return to dashboard" })
            ] })
          ]
        }
      ),
      !isCollapsed && /* @__PURE__ */ jsxs("div", { className: "mt-3 p-2 bg-red-50 border border-red-200 rounded-lg", children: [
        /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-red-700", children: [
          /* @__PURE__ */ jsx(Shield, { className: "h-3 w-3" }),
          /* @__PURE__ */ jsx("span", { className: "text-xs font-medium", children: "Restricted Area" })
        ] }),
        /* @__PURE__ */ jsx("p", { className: "text-xs text-red-600 mt-1", children: "Superadmin access only" })
      ] })
    ] })
  ] });
}
export {
  SuperadminSidebar
};
