"use client";

import Link from "next/link";
import { usePathname } from "next/navigation";
import {
  FileText,
  FolderArchive,
  Settings,
  Building2,
  Globe,
  PiggyBank,
} from "lucide-react";
import { cn } from "@/lib/utils";
import { Separator } from "@/components/ui/separator";
import { Button } from "@/components/ui/button";
import { HistoricalReferences } from "@/components/historical-references";

const QUICK_LINKS = [
  { label: "国家税务总局门户", href: "https://www.chinatax.gov.cn", icon: Building2 },
  { label: "电子税务局", href: "https://etax.chinatax.gov.cn", icon: Globe },
  { label: "公积金管理中心", href: "https://www.12329.com.cn", icon: PiggyBank },
];

export function AppSidebar() {
  const pathname = usePathname();

  const nav = [
    { href: "/workspace", label: "需求与方案", icon: FileText },
    { href: "/finance", label: "财务归档", icon: FolderArchive },
    { href: "/settings", label: "设置", icon: Settings },
  ];

  return (
    <aside className="flex w-56 flex-col border-r bg-card text-card-foreground">
      <div className="p-4">
        <Link href="/" className="font-semibold text-foreground">
          Ops-Core
        </Link>
        <p className="text-xs text-muted-foreground mt-0.5">自动化办公中台</p>
      </div>
      <Separator />
      <nav className="flex flex-1 flex-col gap-1 p-2">
        {nav.map((item) => (
          <Link key={item.href} href={item.href}>
            <Button
              variant={pathname === item.href ? "secondary" : "ghost"}
              size="sm"
              className="w-full justify-start"
            >
              <item.icon className="mr-2 h-4 w-4" />
              {item.label}
            </Button>
          </Link>
        ))}
      </nav>
      <Separator />
      <div className="p-2">
        <p className="text-xs font-medium text-muted-foreground px-2 mb-2">
          快捷门户
        </p>
        <div className="flex flex-col gap-1">
          {QUICK_LINKS.map((link) => (
            <a
              key={link.href}
              href={link.href}
              target="_blank"
              rel="noopener noreferrer"
              className={cn(
                "flex items-center gap-2 rounded-md px-2 py-1.5 text-sm text-muted-foreground hover:bg-accent hover:text-accent-foreground"
              )}
            >
              <link.icon className="h-4 w-4 shrink-0" />
              {link.label}
            </a>
          ))}
        </div>
      </div>
      {pathname === "/workspace" && <HistoricalReferences />}
    </aside>
  );
}
