import { useState } from 'react';
import { Plus, ShieldCheck, Clock, Check, AlertTriangle, QrCode, FileText, Eye } from 'lucide-react';
import Button from "@/components/common/button";
import { permitsData, workPermitFilters } from '@/constants/constant';
import FilterTabs from '@/components/common/roundedFilters';
import StatCard from '@/components/common/dashStatCard';
import InfoBanner from '@/components/common/infoBanner';
import Table from '@/components/common/dataTable';
import { workPermitHeaders, workPermitRows } from '@/constants/tabledata';

export default function WorkPermitPortal() {
 
  const [activeFilter, setActiveFilter] = useState<string>('All');

  // Permit Data matching the UI
 



  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 text-slate-500 uppercase font-mono">
            <span className="text-teal-400">Apple One — HQ Tower</span>
            <span className='text-gray-600'>•</span>
            <span className='text-gray-400'>Operations</span>
            <span className='text-gray-600'>•</span>
            <span className='text-gray-400'>Work Permit</span>
          </div>
          <h1 className="text-2xl font-bold text-white tracking-tight mt-2">
            Permit to Work
          </h1>
          <p className="text-sm font-medium text-slate-400 mt-2 max-w-xl leading-relaxed">
            A controlled permit-to-work lifecycle — request, risk review, approval, activation and close-out — per site and hazard type. QR-driven on the floor.
          </p>
        </div>

        {/* Action Buttons */}
        <div className="flex items-center gap-3 self-start md:mt-10">
          <Button className="flex items-center gap-2 bg-[#0b1727] hover:bg-slate-800/60 text-slate-200 border border-slate-800 rounded-lg px-4 py-2 text-xs font-semibold transition-colors">
            <QrCode size={16} />
            <span>Scan QR</span>
          </Button>

          <Button className="flex items-center gap-2 bg-teal-400 hover:bg-teal-300 text-slate-950 font-bold rounded-lg px-4 py-2 text-xs transition-colors">
            <Plus size={16} className="stroke-[3]" />
            <span>New permit</span>
          </Button>
        </div>
      </div>

      

      {/* --- STAT CARDS --- */}
      <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 mb-6">
        {/* Active on site */}
        <StatCard 
          variant="icon" 
          title="Active on site" 
          value="2" 
          icon={ShieldCheck} 
          badgeText="live" 
          badgeClassName="text-teal-400 font-mono font-medium"
          iconContainerClassName="bg-emerald-950/60 border-emerald-800/40 text-emerald-400"
        />
        
        {/* Awaiting approval */}
        <StatCard 
          variant="icon" 
          title="Awaiting approval" 
          value="3" 
          icon={Clock} 
          badgeText="action due" 
          badgeClassName="text-amber-500 font-mono font-medium"
          iconContainerClassName="bg-amber-950/40 border-amber-800/30 text-amber-500"
        />

        {/* Approved · ready */}
        <StatCard 
          variant="icon" 
          title="Approved · ready" 
          value="1" 
          icon={Check} 
          badgeText="to activate" 
          badgeClassName="text-slate-400 font-mono"
          iconContainerClassName="bg-blue-950/50 border-blue-800/30 text-blue-400"
        />
          
        {/* Expired · breach */}
        <StatCard 
          variant="icon" 
          title="Expired · breach" 
          value="1" 
          icon={AlertTriangle} 
          badgeText="escalate" 
          badgeClassName="text-rose-400 font-mono font-medium"
          iconContainerClassName="bg-rose-950/50 border-rose-800/30 text-rose-400"
        />
      </div>

      {/* --- STATUS PILL FILTERS --- */}
      <div className="mb-6">
        <FilterTabs
          options={workPermitFilters}
          activeFilter={activeFilter}
          onChange={setActiveFilter}
        />
      </div>

      {/* --- PERMIT TABLE SECTION --- */}
      <div className="bg-[#0b1329] border border-slate-800/80 rounded-lg overflow-x-auto">
       <Table headers={workPermitHeaders} rows={workPermitRows}/>
      </div>

       <div className="mb-10 mt-10">
              <InfoBanner 
                boldText="Compliance:" 
                normalText="a permit must be Approved before work starts and Closed on completion. Permits past their validity window auto-flag as Expired for safety escalation." 
              />
            </div>
    </div>
  );
}