"use client";

import React from "react";
import Link from "next/link";
import { Award, ChevronRight, FileSpreadsheet } from "lucide-react";
import { toast } from "sonner";

interface SemesterAprItem {
  semester: string;
  totalStudents: number;
  eligible: number;
  condoned: number;
  detained: number;
  overallAttendance: number;
}

const aprData: SemesterAprItem[] = [
  { semester: "Semester I (Batch 2026)", totalStudents: 280, eligible: 258, condoned: 16, detained: 6, overallAttendance: 84.5 },
  { semester: "Semester III (Batch 2025)", totalStudents: 265, eligible: 249, condoned: 12, detained: 4, overallAttendance: 86.2 },
  { semester: "Semester V (Batch 2024)", totalStudents: 240, eligible: 232, condoned: 6, detained: 2, overallAttendance: 89.1 },
];

export default function SemesterAprPage() {
  return (
    <div className="space-y-5 font-sans">
      <div className="flex flex-col lg:flex-row lg:items-center justify-between gap-4">
        <div>
          <nav className="flex items-center gap-1.5 text-[13px] text-[#64748B] mb-1 font-medium font-sans">
            <Link href="/admin/dashboard" className="hover:text-[#1769E8] hover:underline">
              Home
            </Link>
            <ChevronRight className="w-3.5 h-3.5 text-[#94A3B8]" />
            <Link href="/admin/apr" className="hover:text-[#1769E8] hover:underline">
              Examinations
            </Link>
            <ChevronRight className="w-3.5 h-3.5 text-[#94A3B8]" />
            <span className="text-[#071A4D] font-semibold">Semester APR</span>
          </nav>

          <h1 className="text-3xl font-bold font-heading text-[#071A4D] tracking-tight">
            Semester Annual Performance Report (APR)
          </h1>
          <p className="text-[15px] text-[#64748B] mt-1 font-normal font-sans">
            Official NCHMCT final exam eligibility certification and detention statistics.
          </p>
        </div>

        <button
          onClick={() => toast.success("Exporting Semester APR Register...")}
          className="inline-flex items-center gap-1.5 px-3.5 py-2 text-xs font-semibold text-[#071A4D] bg-white border border-[#E5EAF0] rounded-lg hover:bg-slate-50 transition-colors shadow-2xs cursor-pointer"
        >
          <FileSpreadsheet className="w-4 h-4 text-emerald-600" />
          <span>Export APR Report</span>
        </button>
      </div>

      <div className="rounded-xl bg-white border border-[#E5EAF0] shadow-2xs overflow-hidden">
        <div className="overflow-x-auto">
          <table className="w-full text-left text-xs border-collapse">
            <thead>
              <tr className="bg-[#F8FAFC] border-b border-[#E5EAF0] text-[#64748B] uppercase tracking-wider font-bold text-[11px]">
                <th className="py-3 px-3">Academic Semester</th>
                <th className="py-3 px-3 text-center">Total Enrolled</th>
                <th className="py-3 px-3 text-center">Eligible (≥75%)</th>
                <th className="py-3 px-3 text-center">Condoned (65-74%)</th>
                <th className="py-3 px-3 text-center">Detained (&lt;65%)</th>
                <th className="py-3 px-3 text-center">Average Attendance</th>
              </tr>
            </thead>
            <tbody className="divide-y divide-[#E5EAF0] text-[#334155]">
              {aprData.map((item) => (
                <tr key={item.semester} className="hover:bg-[#F8FAFC] transition-colors">
                  <td className="py-3.5 px-3 font-semibold text-[#071A4D]">{item.semester}</td>
                  <td className="py-3.5 px-3 text-center font-bold text-[#071A4D]">{item.totalStudents}</td>
                  <td className="py-3.5 px-3 text-center font-bold text-emerald-700">{item.eligible}</td>
                  <td className="py-3.5 px-3 text-center font-bold text-amber-700">{item.condoned}</td>
                  <td className="py-3.5 px-3 text-center font-bold text-red-600">{item.detained}</td>
                  <td className="py-3.5 px-3 text-center font-mono font-bold text-[#1769E8]">
                    {item.overallAttendance}%
                  </td>
                </tr>
              ))}
            </tbody>
          </table>
        </div>
      </div>
    </div>
  );
}
