import { useState } from 'react';
import { 
  Target, 
  AlertTriangle, 
  Clock, 
  ShieldCheck, 
  Search, 
  QrCode, 
  Plus, 
  Download, 
  Upload 
} from 'lucide-react';
import Button from "@/utils/button";
import StatCard from "@/utils/dashStatCard";
import LocationTable from '../../utils/table';
import NavigationTabs from '@/utils/tabs';
import { equipmentTabs } from '@/constants/constant';

export default function EquipmentPortal() {
  const [activeTab, setActiveTab] = useState<string>('Site-Wise Equipment');

  

  return (
    <div className="my-15 text-slate-100 max-w-7xl mx-auto 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>Operations</span>
            <span>•</span>
            <span>Equipment</span>
          </div>
          <h1 className="text-2xl font-bold text-white tracking-tight mt-2">
            Equipment & maintenance
          </h1>
          <p className="text-sm font-medium text-slate-400 mt-2 max-w-xl leading-relaxed">
            Asset register, preventive (PPM) and contract (AMC) maintenance, scoped to the active tenant.
          </p>
        </div>
      </div>

    
 {/* Navigation Tabs */}
      <NavigationTabs
        tabs={equipmentTabs}
        activeTab={activeTab}
        onTabChange={setActiveTab}
        className="mb-6"
      />
      {/* --- STAT CARDS --- */}
      <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 mb-6">
        {/* Total Equipment */}
        <StatCard 
          variant="icon" 
          title="Total equipment" 
          value="8" 
          icon={Target} 
          badgeText="4 groups" 
          badgeClassName="text-slate-400 lowercase font-mono"
          iconContainerClassName="bg-cyan-950/40 border-cyan-800/30 text-cyan-400"
        />
        
        {/* Critical Assets */}
        <StatCard 
          variant="icon" 
          title="Critical assets" 
          value="3" 
          icon={AlertTriangle} 
          badgeText="priority" 
          badgeClassName="text-rose-400 lowercase font-mono"
          iconContainerClassName="bg-rose-950/40 border-rose-800/30 text-rose-400"
        />

        {/* PPM Attention */}
        <StatCard 
          variant="icon" 
          title="PPM attention" 
          value="5" 
          icon={Clock} 
          badgeText="due / overdue" 
          badgeClassName="text-amber-400 lowercase font-mono"
          iconContainerClassName="bg-amber-950/40 border-amber-800/30 text-amber-400"
        />
          
        {/* On Plan */}
        <StatCard 
          variant="icon" 
          title="On plan" 
          value="3" 
          icon={ShieldCheck} 
          badgeText="healthy" 
          badgeClassName="text-emerald-400 lowercase font-mono"
          iconContainerClassName="bg-emerald-950/40 border-emerald-800/30 text-emerald-400"
        />
      </div>

      {/* --- ROW 2: SEARCH, FILTERS & ACTION BUTTONS --- */}
      <div className="flex flex-col md:flex-row items-center justify-between gap-4 mb-8">
        {/* Search & Select Filters */}
        <div className="flex flex-1 flex-wrap items-center gap-3 w-full md:w-auto">
          {/* Search Bar */}
          <div className="relative flex-1 min-w-[240px] max-w-md">
            <Search size={18} className="absolute left-3 top-1/2 -translate-y-1/2 text-slate-400" />
            <input
              type="text"
              placeholder="Search code, name, block, provider..."
              className="w-full bg-[#0b1727] border border-slate-800 rounded-lg pl-9 pr-4 py-2 text-xs text-slate-200 placeholder-slate-500 focus:outline-none focus:border-teal-500/50 transition-colors"
            />
          </div>

          {/* Groups Dropdown */}
          <select className="bg-[#0b1727] border border-slate-800 rounded-lg px-4 py-2 text-xs font-semibold text-slate-200 cursor-pointer focus:outline-none focus:border-teal-500/50 transition-all">
            <option value="all">All groups</option>
            <option value="group 1">HVAC</option>
           
             <option value="group 1">Electrical</option>
              <option value="group 3">Plumbing</option>
            <option value="group 4">Fire</option>
          </select>
        </div>

        {/* Action Buttons */}
        <div className="flex items-center gap-3 w-full md:w-auto justify-end">
          <Button className="flex items-center gap-2 bg-[#0b1727] hover:bg-slate-800/60 text-slate-200 border border-slate-800 rounded-lg px-3.5 py-2 text-xs font-semibold transition-colors">
            <QrCode size={15} />
            <span>All QR</span>
          </Button>

          <Button className="flex items-center gap-2 bg-[#0b1727] hover:bg-slate-800/60 text-slate-200 border border-slate-800 rounded-lg px-3.5 py-2 text-xs font-semibold transition-colors">
            <Download size={15} />
            <span>Download</span>
          </Button>

          <Button className="flex items-center gap-2 bg-[#0b1727] hover:bg-slate-800/60 text-slate-200 border border-slate-800 rounded-lg px-3.5 py-2 text-xs font-semibold transition-colors">
            <Upload size={15} />
            <span>Bulk upload</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>Add equipment</span>
          </Button>
        </div>
      </div>

      <LocationTable />
    </div>
  );
}