import { useState } from 'react';
import { 
  Star, 
  ShieldCheck, 
  Activity, 
  Clock, 
  BarChart2, 
  Plus 
} from "lucide-react";
import Button from "@/utils/button";
import StatCard from "@/utils/dashStatCard";
import InfoBanner from "@/utils/infoBanner";
import FilterTabs from '@/utils/roundedFilters';
import { visitorFilters } from '@/constants/constant';
import Table from '@/utils/dataTable';

export default function VistiorManagementPortal() {
    const headers = [
  "Pass",
  "Visitor",
  "Company",
  "Host",
  "Purpose",
  "Type",
  "In",
  "Out",
  "Status",
  "",
];
const Badge = ({
  text,
  color,
}: {
  text: string;
  color: string;
}) => (
  <span
    className={`inline-flex items-center rounded-full px-3 py-1 text-[10px] font-bold uppercase tracking-wider ${color}`}
  >
    <span className="mr-1.5 h-1.5 w-1.5 rounded-full bg-current"></span>
    {text}
  </span>
);

const rows = [
  [
    <span className="font-semibold text-[#2EE6C5]">VIS-4145</span>,
    <span className="font-semibold text-slate-100">Rahul Mehta</span>,
    "Voltas Ltd",
    "Dhananjay T.",
    "Maintenance visit",
    <span className="px-3 py-1 rounded-lg bg-slate-900 border border-slate-700 text-xs">Contractor</span>,
    "09:12",
    "—",
    <Badge text="Checked-In" color="bg-emerald-500/15 text-emerald-400" />,
    <Button className="text-teal-400 font-semibold hover:text-teal-300">Check out</Button>,
  ],

  [
    <span className="font-semibold text-[#2EE6C5]">VIS-4146</span>,
    <span className="font-semibold text-slate-100">Anita Desai</span>,
    "Siemens",
    "ME Local",
    "Interview",
    <span className="px-3 py-1 rounded-lg bg-slate-900 border border-slate-700 text-xs">Interview</span>,
    "—",
    "—",
    <Badge text="Expected" color="bg-blue-500/15 text-blue-400" />,
    <Button className="text-emerald-400 font-semibold hover:text-emerald-300">Check in</Button>,
  ],

  [
    <span className="font-semibold text-[#2EE6C5]">VIS-4147</span>,
    <span className="font-semibold text-slate-100">Karthik R.</span>,
    "Schindler",
    "Site FM Lead",
    "Client meeting",
    <span className="px-3 py-1 rounded-lg bg-slate-900 border border-slate-700 text-xs">Guest</span>,
    "08:05",
    "10:40",
    <Badge text="Checked-Out" color="bg-slate-700 text-slate-400" />,
    <span className="text-slate-500">—</span>,
  ],

  [
    <span className="font-semibold text-[#2EE6C5]">VIS-4148</span>,
    <span className="font-semibold text-slate-100">Priya Nair</span>,
    "Amazon Logistics",
    "Estates Office",
    "Material delivery",
    <span className="px-3 py-1 rounded-lg bg-slate-900 border border-slate-700 text-xs">Delivery</span>,
    "—",
    "—",
    <Badge text="Pre-Reg" color="bg-yellow-500/15 text-yellow-400" />,
    <Button className="text-emerald-400 font-semibold hover:text-emerald-300">Check in</Button>,
  ],

  [
    <span className="font-semibold text-[#2EE6C5]">VIS-4149</span>,
    <span className="font-semibold text-slate-100">Imran Q.</span>,
    "FreshMenu",
    "TECH Local",
    "AMC service",
    <span className="px-3 py-1 rounded-lg bg-slate-900 border border-slate-700 text-xs">Contractor</span>,
    "10:30",
    "—",
    <Badge text="Checked-In" color="bg-emerald-500/15 text-emerald-400" />,
    <Button className="text-teal-400 font-semibold hover:text-teal-300">Check out</Button>,
  ],
   [
    <span className="font-semibold text-[#2EE6C5]">VIS-4145</span>,
    <span className="font-semibold text-slate-100">Rahul Mehta</span>,
    "Voltas Ltd",
    "Dhananjay T.",
    "Maintenance visit",
    <span className="px-3 py-1 rounded-lg bg-slate-900 border border-slate-700 text-xs">Contractor</span>,
    "09:12",
    "—",
    <Badge text="Checked-In" color="bg-emerald-500/15 text-emerald-400" />,
    <Button className="text-teal-400 font-semibold hover:text-teal-300">Check out</Button>,
  ],

  [
    <span className="font-semibold text-[#2EE6C5]">VIS-4146</span>,
    <span className="font-semibold text-slate-100">Anita Desai</span>,
    "Siemens",
    "ME Local",
    "Interview",
    <span className="px-3 py-1 rounded-lg bg-slate-900 border border-slate-700 text-xs">Interview</span>,
    "—",
    "—",
    <Badge text="Expected" color="bg-blue-500/15 text-blue-400" />,
    <Button className="text-emerald-400 font-semibold hover:text-emerald-300">Check in</Button>,
  ],

  [
    <span className="font-semibold text-[#2EE6C5]">VIS-4147</span>,
    <span className="font-semibold text-slate-100">Karthik R.</span>,
    "Schindler",
    "Site FM Lead",
    "Client meeting",
    <span className="px-3 py-1 rounded-lg bg-slate-900 border border-slate-700 text-xs">Guest</span>,
    "08:05",
    "10:40",
    <Badge text="Checked-Out" color="bg-slate-700 text-slate-400" />,
    <span className="text-slate-500">—</span>,
  ],

  [
    <span className="font-semibold text-[#2EE6C5]">VIS-4148</span>,
    <span className="font-semibold text-slate-100">Priya Nair</span>,
    "Amazon Logistics",
    "Estates Office",
    "Material delivery",
    <span className="px-3 py-1 rounded-lg bg-slate-900 border border-slate-700 text-xs">Delivery</span>,
    "—",
    "—",
    <Badge text="Pre-Reg" color="bg-yellow-500/15 text-yellow-400" />,
    <Button className="text-emerald-400 font-semibold hover:text-emerald-300">Check in</Button>,
  ],

  [
    <span className="font-semibold text-[#2EE6C5]">VIS-4149</span>,
    <span className="font-semibold text-slate-100">Imran Q.</span>,
    "FreshMenu",
    "TECH Local",
    "AMC service",
    <span className="px-3 py-1 rounded-lg bg-slate-900 border border-slate-700 text-xs">Contractor</span>,
    "10:30",
    "—",
    <Badge text="Checked-In" color="bg-emerald-500/15 text-emerald-400" />,
    <Button className="text-teal-400 font-semibold hover:text-teal-300">Check out</Button>,
  ],
];
 
const [activeFilter, setActiveFilter] = useState<string>('All');
  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-[10px] font-bold tracking-widest text-slate-500 uppercase font-mono">
            <span className="text-teal-400">Apple One — HQ Tower</span>
            <span>•</span>
            <span>Workplace</span>
            <span>•</span>
            <span>Visitors</span>
          </div>
          <h1 className="text-2xl font-bold text-white tracking-tight mt-2">
            Visitor management
          </h1>
          <p className="text-sm font-medium text-slate-400 mt-2 max-w-xl leading-relaxed">
          Pre-registration, QR / OTP check-in, host notifications and on-site visitor tracking with a full audit trail.
          </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">
            <BarChart2 className="w-4 h-4 text-slate-300" />
            <span>Scan QR</span>
          </Button>

          <Button className="bg-teal-400 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>Pre Register</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 vendors */}
        <StatCard
          variant="icon"
          title="Active vendors"
          value="6"
          icon={Star}
          badgeText="contracted"
          badgeClassName="text-slate-400 lowercase font-mono"
          iconContainerClassName="bg-cyan-950/40 border-cyan-800/30 text-cyan-400"
        />

        {/* Avg SLA adherence */}
        <StatCard
          variant="icon"
          title="Avg SLA adherence"
          value="93%"
          icon={ShieldCheck}
          badgeText="this month"
          badgeClassName="text-teal-400 lowercase font-mono font-medium"
          iconContainerClassName="bg-emerald-950/60 border-emerald-800/40 text-emerald-400"
        />

        {/* Open field jobs */}
        <StatCard
          variant="icon"
          title="Open field jobs"
          value="12"
          icon={Activity}
          badgeText="in progress"
          badgeClassName="text-cyan-400 lowercase font-mono"
          iconContainerClassName="bg-blue-950/50 border-blue-800/30 text-blue-400"
        />

        {/* Avg response time */}
        <StatCard
          variant="icon"
          title="Avg response time"
          value="2.7h"
          icon={Clock}
          badgeText="to site"
          badgeClassName="text-slate-400 lowercase font-mono"
          iconContainerClassName="bg-amber-950/40 border-amber-800/30 text-amber-500"
        />
      </div>

      {/* --- STATUS PILL FILTERS --- */}
            <div className="mb-6">
              <FilterTabs
                options={visitorFilters}
                activeFilter={activeFilter}
                onChange={setActiveFilter}
              />
            </div>
<Table headers={headers} rows={rows}/>
             
 <div className="mb-10 mt-10">
              <InfoBanner 
                boldText="Flow:" 
                normalText="host pre-registers → visitor receives QR + OTP → reception scans for check-in (ID & photo captured) → host notified → auto check-out on exit. Denied visitors are held on a site watchlist." 
              />
            </div>
    
        
       
    </div>
  );
}