"use client"

import Link from "next/link"
import { usePathname } from "next/navigation"
import { useAuth } from "@/hooks/use-auth"
import {
  SidebarGroup,
  SidebarGroupLabel,
  SidebarGroupContent,
  SidebarMenu,
  SidebarMenuItem,
  SidebarMenuButton,
} from "@/components/ui/sidebar"
import {
  HardDriveIcon,
  ListIcon,
  PlugIcon,
  WorkflowIcon,
  FileTextIcon,
  CopyIcon,
} from "lucide-react"

const ADMIN_LINKS = [
  { href: "/admin/storage", label: "Storage", icon: HardDriveIcon },
  { href: "/admin/jobs", label: "Jobs", icon: ListIcon },
  { href: "/admin/plugins", label: "Plugins", icon: PlugIcon },
  { href: "/admin/pipelines", label: "Pipelines", icon: WorkflowIcon },
  { href: "/admin/sidecars", label: "Sidecars", icon: FileTextIcon },
  { href: "/admin/duplicates", label: "Duplicates", icon: CopyIcon },
]

export function AdminSidebar() {
  const { isAdmin } = useAuth()
  const pathname = usePathname()

  if (!isAdmin) return null

  return (
    <SidebarGroup>
      <SidebarGroupLabel>Admin</SidebarGroupLabel>
      <SidebarGroupContent>
        <SidebarMenu>
          {ADMIN_LINKS.map(({ href, label, icon: Icon }) => (
            <SidebarMenuItem key={href}>
              <SidebarMenuButton asChild isActive={pathname === href}>
                <Link href={href}>
                  <Icon className="h-4 w-4" />
                  <span>{label}</span>
                </Link>
              </SidebarMenuButton>
            </SidebarMenuItem>
          ))}
        </SidebarMenu>
      </SidebarGroupContent>
    </SidebarGroup>
  )
}
