"use client";

import React, { useState } from "react";
import { CalendarDays, Filter, Search } from "lucide-react";
import { StatusBadge } from "@/components/shared/status-badge";
import { AttendanceCode } from "@/types/attendance";

interface WardHistoryItem {
  id: string;
  date: string;
  time: string;
  subjectCode: string;
  subjectName: string;
  hours: number;
  statusCode: AttendanceCode;
  remarks?: string;
}

const mockWardHistory: WardHistoryItem[] = [
  {
    id: "wh-1",
    date: "07-Oct-2026",
    time: "09:00 – 13:00",
    subjectCode: "BHM201",
    subjectName: "Food Production Operations Practical",
    hours: 4.0,
    statusCode: "P",
  },
  {
    id: "wh-2",
    date: "06-Oct-2026",
    time: "09:00 – 13:00",
    subjectCode: "BHM201",
    subjectName: "Food Production Operations Practical",
    hours: 4.0,
    statusCode: "P",
  },
  {
    id: "wh-3",
    date: "05-Oct-2026",
    time: "14:00 – 15:00",
    subjectCode: "BHM202",
    subjectName: "Food & Beverage Service Theory",
    hours: 1.0,
    statusCode: "P",
  },
  {
    id: "wh-4",
    date: "02-Oct-2026",
    time: "09:00 – 13:00",
    subjectCode: "BHM201",
    subjectName: "Food Production Operations Practical",
    hours: 4.0,
    statusCode: "H",
    remarks: "Gandhi Jayanti (Gazetted Holiday)",
  },
  {
    id: "wh-5",
    date: "29-Sep-2026",
    time: "09:00 – 13:00",
    subjectCode: "BHM203",
    subjectName: "Bakery & Confectionery Practical",
    hours: 4.0,
    statusCode: "P",
  },
];

export default function ParentAttendanceHistoryPage() {
  const [records, setRecords] = useState<WardHistoryItem[]>(mockWardHistory);
  const [search, setSearch] = useState("");

  const filtered = records.filter(
    (r) =>
      r.subjectCode.toLowerCase().includes(search.toLowerCase()) ||
      r.subjectName.toLowerCase().includes(search.toLowerCase()) ||
      r.date.includes(search)
  );

  return (
    <div className="space-y-6">
      {/* Header */}
      <div className="border-b border-slate-200 pb-4 dark:border-slate-800">
        <div className="flex items-center gap-1.5 text-xs text-slate-500 mb-0.5">
          <CalendarDays className="w-3.5 h-3.5" />
          <span>Attendance Log</span>
        </div>
        <h1 className="text-xl font-bold text-slate-900 tracking-tight dark:text-slate-100">
          Ward Class Attendance Log: Aaron Smith
        </h1>
        <p className="text-xs text-slate-500 mt-0.5">
          Verified daily classroom and kitchen presence records for your ward.
        </p>
      </div>

      {/* Table */}
      <div className="rounded-lg border border-slate-200 bg-white overflow-hidden shadow-sm dark:border-slate-800 dark:bg-slate-900">
        <div className="overflow-x-auto">
          <table className="w-full text-left text-xs border-collapse">
            <thead>
              <tr className="bg-slate-50 border-b border-slate-200 text-slate-500 font-semibold uppercase tracking-wider dark:bg-slate-900/50 dark:border-slate-800">
                <th className="py-3 px-4">Date</th>
                <th className="py-3 px-4">Time Window</th>
                <th className="py-3 px-4">Subject</th>
                <th className="py-3 px-4 text-center">Contact Hours</th>
                <th className="py-3 px-4">Status Code</th>
                <th className="py-3 px-4">Notes</th>
              </tr>
            </thead>
            <tbody className="divide-y divide-slate-100 dark:divide-slate-800">
              {filtered.map((r) => (
                <tr
                  key={r.id}
                  className="hover:bg-slate-50/75 transition-colors dark:hover:bg-slate-800/40"
                >
                  <td className="py-3 px-4 font-mono font-bold text-slate-900 dark:text-slate-100">
                    {r.date}
                  </td>
                  <td className="py-3 px-4 font-mono text-slate-500">{r.time}</td>
                  <td className="py-3 px-4">
                    <span className="font-mono font-bold text-blue-600 dark:text-blue-400 mr-1.5">
                      {r.subjectCode}
                    </span>
                    <span className="font-medium text-slate-800 dark:text-slate-200">
                      {r.subjectName}
                    </span>
                  </td>
                  <td className="py-3 px-4 text-center font-mono font-bold text-slate-900 dark:text-slate-100">
                    {r.hours}h
                  </td>
                  <td className="py-3 px-4">
                    <StatusBadge code={r.statusCode} />
                  </td>
                  <td className="py-3 px-4 text-slate-500 text-[11px]">
                    {r.remarks || "Regular session"}
                  </td>
                </tr>
              ))}
            </tbody>
          </table>
        </div>
      </div>
    </div>
  );
}
