"use client";

import React, { useState } from "react";
import Link from "next/link";
import {
  Briefcase,
  Search,
  RotateCcw,
  Plus,
  Eye,
  ChevronRight,
  FileSpreadsheet,
  Building,
} from "lucide-react";
import { toast } from "sonner";

interface PlacementDrive {
  id: string;
  companyName: string;
  role: string;
  ctc: string;
  studentsPlaced: number;
  driveDate: string;
  status: "Completed" | "Ongoing" | "Scheduled";
}

const sampleDrives: PlacementDrive[] = [
  {
    id: "pl-1",
    companyName: "Taj Hotels (IHCL)",
    role: "Management Trainee - Hotel Operations",
    ctc: "₹ 5.2 LPA",
    studentsPlaced: 18,
    driveDate: "12 Sep 2026",
    status: "Completed",
  },
  {
    id: "pl-2",
    companyName: "The Oberoi Group (OCER)",
    role: "Executive Trainee - Culinary & F&B",
    ctc: "₹ 5.8 LPA",
    studentsPlaced: 12,
    driveDate: "24 Sep 2026",
    status: "Completed",
  },
  {
    id: "pl-3",
    companyName: "Marriott International",
    role: "Voyage Leadership Development Program",
    ctc: "₹ 4.8 LPA",
    studentsPlaced: 22,
    driveDate: "05 Oct 2026",
    status: "Ongoing",
  },
  {
    id: "pl-4",
    companyName: "ITC Hotels",
    role: "Management Trainee",
    ctc: "₹ 5.0 LPA",
    studentsPlaced: 0,
    driveDate: "20 Oct 2026",
    status: "Scheduled",
  },
];

export default function PlacementsPage() {
  const [search, setSearch] = useState("");

  const filtered = sampleDrives.filter(
    (d) =>
      d.companyName.toLowerCase().includes(search.toLowerCase()) ||
      d.role.toLowerCase().includes(search.toLowerCase())
  );

  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]" />
            <span className="text-[#071A4D] font-semibold">Placements</span>
          </nav>

          <h1 className="text-3xl font-bold font-heading text-[#071A4D] tracking-tight">
            Campus Placement Cell
          </h1>
          <p className="text-[15px] text-[#64748B] mt-1 font-normal font-sans">
            Manage corporate campus recruitments, hospitality brand drives, and offer letters.
          </p>
        </div>

        <div className="flex items-center gap-2.5 flex-wrap">
          <button
            onClick={() => toast.success("Exporting Placement Reports...")}
            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 Report</span>
          </button>
          <button
            onClick={() => toast.info("Schedule new recruitment drive...")}
            className="inline-flex items-center gap-1.5 px-4 py-2 text-xs font-semibold text-white bg-[#1769E8] hover:bg-[#1257C7] rounded-lg shadow-sm transition-colors cursor-pointer"
          >
            <Plus className="w-4 h-4" />
            <span>+ Schedule Company Drive</span>
          </button>
        </div>
      </div>

      <div className="rounded-xl bg-white border border-[#E5EAF0] shadow-2xs overflow-hidden">
        <div className="p-4 border-b border-[#E5EAF0] flex items-center justify-between">
          <div className="flex items-center gap-2">
            <Briefcase className="w-4 h-4 text-[#1769E8]" />
            <h2 className="text-sm font-bold font-heading text-[#071A4D]">
              Campus Recruitment Drives ({filtered.length})
            </h2>
          </div>
          <span className="text-xs text-[#64748B] font-medium">Batch 2026 - 2027</span>
        </div>

        <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">Company Brand</th>
                <th className="py-3 px-3">Designation / Role</th>
                <th className="py-3 px-3">Package (CTC)</th>
                <th className="py-3 px-3 text-center">Selected Offers</th>
                <th className="py-3 px-3">Drive Date</th>
                <th className="py-3 px-3 text-center">Status</th>
                <th className="py-3 px-3 text-center">Actions</th>
              </tr>
            </thead>
            <tbody className="divide-y divide-[#E5EAF0] text-[#334155]">
              {filtered.map((item) => (
                <tr key={item.id} className="hover:bg-[#F8FAFC] transition-colors">
                  <td className="py-3.5 px-3 font-semibold text-[#071A4D]">
                    {item.companyName}
                  </td>
                  <td className="py-3.5 px-3 text-[#334155]">
                    {item.role}
                  </td>
                  <td className="py-3.5 px-3 font-mono font-bold text-emerald-700">
                    {item.ctc}
                  </td>
                  <td className="py-3.5 px-3 text-center font-bold text-[#071A4D]">
                    {item.studentsPlaced}
                  </td>
                  <td className="py-3.5 px-3 text-[#64748B]">
                    {item.driveDate}
                  </td>
                  <td className="py-3.5 px-3 text-center">
                    <span
                      className={`inline-block px-2.5 py-0.5 rounded-full text-[11px] font-semibold ${
                        item.status === "Completed"
                          ? "bg-[#DCFCE7] text-[#15803D]"
                          : item.status === "Ongoing"
                          ? "bg-[#FEF3C7] text-[#D97706]"
                          : "bg-[#E2E8F0] text-[#475569]"
                      }`}
                    >
                      {item.status}
                    </span>
                  </td>
                  <td className="py-3.5 px-3 text-center">
                    <button
                      onClick={() => toast.info(`Viewing drive: ${item.companyName}`)}
                      className="p-1 rounded text-[#1769E8] hover:bg-blue-50 transition-colors"
                      title="View Drive"
                    >
                      <Eye className="w-3.5 h-3.5" />
                    </button>
                  </td>
                </tr>
              ))}
            </tbody>
          </table>
        </div>
      </div>
    </div>
  );
}
