"use client";

import * as React from "react";
import {
  Sidebar,
  SidebarContent,
  SidebarFooter,
  SidebarHeader,
  SidebarMenu,
  SidebarMenuButton,
  SidebarMenuItem,
} from "@/components/ui/sidebar";
import { User } from "next-auth";
import { siteConfig } from "@/config/site";
import { NavMain } from "@/components/nav-main";
import { NavUser } from "@/components/nav-user";
import { LifeBuoy, Send, Shield } from "lucide-react";
import { NavSecondary } from "@/components/nav-secondary";

const adminData = {
  navMain: [
    {
      title: "管理面板",
      url: "/dashboard",
      icon: Shield,
      isActive: true,
      items: [
        { title: "管理员管理", url: "/dashboard/usermanagement/admin" },
        { title: "学生管理", url: "/dashboard/usermanagement/student" },
        { title: "教师管理", url: "/dashboard/usermanagement/teacher" },
        { title: "题目管理", url: "/dashboard/usermanagement/problem" },
      ],
    },
  ],
  navSecondary: [
    { title: "帮助", url: `${siteConfig.url.repo.github}/issues`, icon: LifeBuoy },
    { title: "反馈", url: `${siteConfig.url.repo.github}/pulls`, icon: Send },
  ],
};

interface AdminSidebarProps {
  user: User;
}

export function AdminSidebar({
  user,
  ...props
}: AdminSidebarProps & React.ComponentProps<typeof Sidebar>) {
  const userInfo = {
    name: user.name ?? "管理员",
    email: user.email ?? "",
    avatar: user.image ?? "/avatars/default.jpg",
  };

  return (
    <Sidebar {...props}>
      <SidebarHeader>
        <SidebarMenu>
          <SidebarMenuItem>
            <SidebarMenuButton size="lg" asChild>
              <a href="#">
                <div className="flex aspect-square size-8 items-center justify-center rounded-lg bg-sidebar-primary text-sidebar-primary-foreground">
                  <Shield className="size-4" />
                </div>
                <div className="grid flex-1 text-left text-sm leading-tight">
                  <span className="truncate font-semibold">Admin</span>
                  <span className="truncate text-xs">管理后台</span>
                </div>
              </a>
            </SidebarMenuButton>
          </SidebarMenuItem>
        </SidebarMenu>
      </SidebarHeader>
      <SidebarContent>
        <NavMain items={adminData.navMain} />
        <NavSecondary items={adminData.navSecondary} className="mt-auto" />
      </SidebarContent>
      <SidebarFooter>
        <NavUser user={userInfo} />
      </SidebarFooter>
    </Sidebar>
  );
}
