import Link from "next/link";
import { CopyIcon, HomeIcon, SettingsIcon, UsersIcon, UtensilsIcon, LayoutGridIcon, ChefHatIcon, ContactIcon, BanknoteIcon, UserIcon, LogOutIcon, ShieldAlertIcon } from "lucide-react";
import { signOut } from "next-auth/react";
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from "@/components/ui/alert-dialog";

export function Sidebar() {
  return (
    <aside className="w-64 border-l bg-card flex flex-col h-screen fixed right-0 top-0">
      <div className="h-16 flex items-center justify-center border-b px-4">
        <h1 className="font-bold text-xl text-primary">مدیریت توکان</h1>
      </div>
      <nav className="flex-1 p-4 space-y-2 overflow-y-auto">
        <Link href="/" className="flex items-center gap-3 px-3 py-2 rounded-md hover:bg-accent text-foreground">
          <HomeIcon className="w-5 h-5" />
          <span>داشبورد</span>
        </Link>
        <Link href="/orders" className="flex items-center gap-3 px-3 py-2 rounded-md hover:bg-accent text-foreground">
          <CopyIcon className="w-5 h-5" />
          <span>سفارشات</span>
        </Link>
        <Link href="/halls" className="flex items-center gap-3 px-3 py-2 rounded-md hover:bg-accent text-foreground">
          <LayoutGridIcon className="w-5 h-5" />
          <span>سالن‌ها و میزها</span>
        </Link>
        <Link href="/stations" className="flex items-center gap-3 px-3 py-2 rounded-md hover:bg-accent text-foreground">
          <ChefHatIcon className="w-5 h-5" />
          <span>بخش‌های آماده‌سازی</span>
        </Link>
        <Link href="/menu" className="flex items-center gap-3 px-3 py-2 rounded-md hover:bg-accent text-foreground">
          <UtensilsIcon className="w-5 h-5" />
          <span>منوی رستوران</span>
        </Link>
        <Link href="/customers" className="flex items-center gap-3 px-3 py-2 rounded-md hover:bg-accent text-foreground">
          <ContactIcon className="w-5 h-5" />
          <span>مشتریان</span>
        </Link>
        <Link href="/users" className="flex items-center gap-3 px-3 py-2 rounded-md hover:bg-accent text-foreground">
          <UsersIcon className="w-5 h-5" />
          <span>پرسنل</span>
        </Link>
        <Link href="/payroll" className="flex items-center gap-3 px-3 py-2 rounded-md hover:bg-accent text-foreground">
          <BanknoteIcon className="w-5 h-5" />
          <span>حقوق و دستمزد</span>
        </Link>
        <Link href="/settings" className="flex items-center gap-3 px-3 py-2 rounded-md hover:bg-accent text-foreground">
          <SettingsIcon className="w-5 h-5" />
          <span>تنظیمات</span>
        </Link>
        <Link href="/audit" className="flex items-center gap-3 px-3 py-2 rounded-md hover:bg-accent text-foreground">
          <ShieldAlertIcon className="w-5 h-5 text-rose-500" />
          <span>لاگ سیستم</span>
        </Link>
        <Link href="/profile" className="flex items-center gap-3 px-3 py-2 rounded-md hover:bg-accent text-indigo-700 bg-indigo-50/50 mt-4 border border-indigo-100">
          <UserIcon className="w-5 h-5" />
          <span className="font-bold">پروفایل کاربری من</span>
        </Link>
      </nav>
      
      <AlertDialog>
        <AlertDialogTrigger asChild>
           <button className="flex w-full items-center gap-3 px-7 py-4 border-t hover:bg-rose-50 text-rose-600 transition-colors">
              <LogOutIcon className="w-5 h-5" />
              <span className="font-bold">توقف و خروج حساب</span>
           </button>
        </AlertDialogTrigger>
        <AlertDialogContent>
           <AlertDialogHeader>
             <AlertDialogTitle>آیا قصد دارید از حساب خارج شوید؟</AlertDialogTitle>
             <AlertDialogDescription>در صورت خروج، برای دسترسی مجدد باید کد پرسنلی و رمز عبور وارد کنید.</AlertDialogDescription>
           </AlertDialogHeader>
           <AlertDialogFooter>
             <AlertDialogCancel>انصراف</AlertDialogCancel>
             <AlertDialogAction onClick={async () => { await signOut({ redirect: false }); window.location.href = "/login"; }} className="bg-rose-600 hover:bg-rose-700">خروج از سیستم</AlertDialogAction>
           </AlertDialogFooter>
        </AlertDialogContent>
      </AlertDialog>

      <div className="p-2 border-t text-xs text-center text-muted-foreground tracking-tighter">
        نسخه ۱.۰.۰
      </div>
    </aside>
  );
}
