import { useState } from 'react';
import { 
  ShieldCheck, 
  Clock, 
  AlertTriangle, 
  Calendar, 
  Layers, 
  Plus 
} from "lucide-react";
import Button from "@/components/common/button";
import StatCard from "@/components/common/dashStatCard";
import Table from '@/components/common/dataTable';
import { firesafetyheaders, firesafetyrows } from '@/constants/tabledata';
import { StatusBadge } from '@/components/common/statusBadge';





export default function FireSafetyPortal() {
  return (
    <div className="my-15 text-slate-100 font-sans">
      {/* --- HEADER SECTION --- */}
      <div className="flex flex-col md:flex-row md:items-start md:justify-between gap-4 mb-6">
        <div>
          <div className="flex items-center gap-2 text-[12px] font-bold tracking-widest uppercase font-mono">
            <span className="text-teal-400">Apple One — HQ Tower</span>
            <span className="text-slate-600">•</span>
            <span className="text-slate-400">COMPLIANCE</span>
            <span className="text-slate-600">•</span>
            <span className="text-slate-400"> FIRE & SAFETY</span>
          </div>
          <h1 className="text-2xl font-bold text-white tracking-tight mt-2">
            Fire & safety management
          </h1>
          <p className="text-sm font-medium text-slate-400 mt-2 max-w-xl leading-relaxed">
            Safety-equipment inspections, drill scheduling, evacuation plans and incident reporting with regulatory compliance tracking.
          </p>
        </div>

        {/* --- HEADER BUTTONS --- */}
        <div className="flex items-center gap-3 self-start md:mt-10">
          <Button className="bg-[#0b1727] hover:bg-slate-800/60 text-slate-200 border border-slate-800 text-xs px-4 py-2 rounded-lg flex items-center gap-2 font-semibold transition-colors">
            <Layers className="w-4 h-4 text-slate-300" />
            <span>Evac plans</span>
          </Button>

          <Button className="bg-[#2dd4bf] hover:bg-teal-300 text-slate-950 font-bold text-xs px-4 py-2 rounded-lg flex items-center gap-2 transition-colors">
            <Plus className="w-4 h-4 stroke-[3]" />
            <span>Schedule drill</span>
          </Button>
        </div>
      </div>

      {/* --- STAT CARDS --- */}
      <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 mb-6">
        {/* Card 1: Equipment compliant */}
        <StatCard
          variant="icon"
          title="Equipment compliant"
          value="4/6"
          icon={ShieldCheck}
          badgeText="inspected"
          badgeClassName="text-emerald-400 lowercase font-mono font-medium"
          iconContainerClassName="bg-emerald-950/60 border-emerald-800/40 text-emerald-400"
        />

        {/* Card 2: Inspections due */}
        <StatCard
          variant="icon"
          title="Inspections due"
          value="2"
          icon={Clock}
          badgeText="this week"
          badgeClassName="text-amber-400 lowercase font-mono"
          iconContainerClassName="bg-amber-950/50 border-amber-800/30 text-amber-400"
        />

        {/* Card 3: Open incidents */}
        <StatCard
          variant="icon"
          title="Open incidents"
          value="1"
          icon={AlertTriangle}
          badgeText="action"
          badgeClassName="text-rose-400 lowercase font-mono"
          iconContainerClassName="bg-rose-950/50 border-rose-800/30 text-rose-400"
        />

        {/* Card 4: Next drill */}
        <StatCard
          variant="icon"
          title="Next drill"
          value="Jul 12"
          icon={Calendar}
          badgeText="Q3 evacuation"
          badgeClassName="text-slate-400 lowercase font-mono"
          iconContainerClassName="bg-blue-950/60 border-blue-800/40 text-blue-400"
        />
      </div>

      {/* --- MAIN CONTENT LAYOUT --- */}
      <div className="grid grid-cols-1 lg:grid-cols-3 gap-4">
        {/* Left Column: Safety equipment inspection Table */}
        <div className="lg:col-span-2 rounded-xl border border-slate-800/80  p-5">
          <div className="flex items-center justify-between mb-4">
            <h2 className="text-base font-bold text-slate-100">
              Safety equipment inspection
            </h2>
            <span className="text-xs font-mono text-slate-500">
              6 asset classes
            </span>
          </div>
          <Table headers={firesafetyheaders} rows={firesafetyrows} />
        </div>

        {/* Right Column: Drill schedule & Incidents */}
        <div className="flex flex-col gap-4">
          {/* Drill schedule Card */}
          <div className="rounded-xl border border-slate-800/80 bg-[#071321]/80 p-5">
            <h2 className="text-base font-bold text-slate-100 mb-6">
              Drill schedule
            </h2>

            <div className="relative pl-6 space-y-6 before:absolute before:left-2 before:top-2 before:bottom-2 before:w-[1px] before:bg-slate-800">
              {/* Timeline Item 1 */}
              <div className="relative">
                <span className="absolute -left-[23px] top-1.5 h-3 w-3 rounded-full border-2 border-teal-400 bg-[#071321]" />
                <h3 className="text-sm font-bold text-slate-100">
                  Q3 full evacuation drill
                </h3>
                <p className="text-xs font-mono text-slate-500 mt-1">
                  Jul 12, 2026 <span className="mx-1">•</span> reserved
                </p>
              </div>

              {/* Timeline Item 2 */}
              <div className="relative">
                <span className="absolute -left-[23px] top-1.5 h-3 w-3 rounded-full border-2 border-teal-400 bg-[#071321]" />
                <h3 className="text-sm font-bold text-slate-100">
                  Wardens refresher
                </h3>
                <p className="text-xs font-mono text-slate-500 mt-1">
                  Jun 30, 2026 <span className="mx-1">•</span> reserved
                </p>
              </div>

              {/* Timeline Item 3 */}
              <div className="relative">
                <span className="absolute -left-[23px] top-1.5 h-3 w-3 rounded-full border-2 border-teal-400 bg-[#071321]" />
                <h3 className="text-sm font-bold text-slate-100">
                  Q2 drill · 92% turnout
                </h3>
                <p className="text-xs font-mono text-slate-500 mt-1">
                  Apr 14, 2026 <span className="mx-1">•</span> completed
                </p>
              </div>
            </div>
          </div>

          {/* Incidents Card */}
          <div className="rounded-xl border border-slate-800/80 bg-[#071321]/80 p-5">
            <h2 className="text-base font-bold text-slate-100 mb-4">
              Incidents
            </h2>

            <div className="space-y-4">
              {/* Incident 1 */}
              <div className="flex items-center justify-between py-2 border-b border-slate-800/60 last:border-0">
                <div>
                  <h3 className="text-sm font-bold text-slate-100">
                    Minor smoke · pantry
                  </h3>
                  <p className="text-xs font-mono text-slate-500 mt-1">
                    INC-21 <span className="mx-1">•</span> Jun 18
                  </p>
                </div>
                <StatusBadge
                  text="CLOSED"
                  color="bg-slate-800/80 text-slate-400"
                />
              </div>

              {/* Incident 2 */}
              <div className="flex items-center justify-between py-2">
                <div>
                  <h3 className="text-sm font-bold text-slate-100">
                    Extinguisher low pressure
                  </h3>
                  <p className="text-xs font-mono text-slate-500 mt-1">
                    INC-22 <span className="mx-1">•</span> Jun 24
                  </p>
                </div>
                <StatusBadge
                  text="OPEN"
                  color="bg-amber-500/15 text-amber-400"
                />
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  );
}