import { useState } from 'react';
import { 
  Snowflake, 
  AlertTriangle, 
  Zap, 
  Check, 
  FileCheck2,
  Sparkles
} from "lucide-react";
import Button from "@/components/common/button";
import StatCard from "@/components/common/dashStatCard";
import Table from '@/components/common/dataTable';
import NavigationTabs from '@/components/common/tabs';

import { connectedassettabs } from '@/constants/tabConstant';
import { connectedassetheaders, connectedassetrows } from '@/constants/tabledata';

export default function ConnectedAssetPortal() {
  const [activeTab, setActiveTab] = useState<string>('Asset Fleet');

  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">INTELLIGENCE</span>
            <span className="text-slate-600">•</span>
            <span className="text-slate-400">CONNECTED ASSETS</span>
          </div>
          <h1 className="text-2xl font-bold text-white tracking-tight mt-2">
            Connected refrigeration & HVAC
          </h1>
          <p className="text-sm font-medium text-slate-400 mt-2 max-w-xl leading-relaxed">
            A vertical solution for temperature-critical assets — live setpoint monitoring, excursion response and AI-driven energy optimisation across every store and plant room.
          </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">
            <FileCheck2 className="w-4 h-4 text-slate-300" />
            <span>HACCP log</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">
            <Sparkles className="w-4 h-4 fill-slate-950" />
            <span>Apply optimisation</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: Connected assets */}
        <StatCard
          variant="icon"
          title="Connected assets"
          value="42"
          icon={Snowflake}
          badgeText="cases · chillers · AHUs"
          badgeClassName="text-slate-400 lowercase font-mono"
          iconContainerClassName="bg-sky-950/60 border-sky-800/40 text-sky-400"
        />

        {/* Card 2: Open excursions */}
        <StatCard
          variant="icon"
          title="Open excursions"
          value="2"
          icon={AlertTriangle}
          badgeText="auto-responded"
          badgeClassName="text-amber-400 lowercase font-mono"
          iconContainerClassName="bg-amber-950/50 border-amber-800/30 text-amber-400"
        />

        {/* Card 3: Energy saved */}
        <StatCard
          variant="icon"
          title="Energy saved"
          value="₹2.1 L"
          icon={Zap}
          badgeText="this month · AI setpoints"
          badgeClassName="text-teal-400 lowercase font-mono"
          iconContainerClassName="bg-teal-950/60 border-teal-800/40 text-teal-400"
        />

        {/* Card 4: Cold-chain uptime */}
        <StatCard
          variant="icon"
          title="Cold-chain uptime"
          value="99.2%"
          icon={Check}
          badgeText="90-day rolling"
          badgeClassName="text-teal-400 lowercase font-mono"
          iconContainerClassName="bg-emerald-950/50 border-emerald-800/30 text-emerald-400"
        />
      </div>

      {/* --- NAVIGATION TABS (UNCHANGED) --- */}
      <NavigationTabs
        tabs={connectedassettabs}
        activeTab={activeTab}
        onTabChange={setActiveTab}
        className="mb-4"
      />

      {/* --- TABLE (UNCHANGED) --- */}
      <Table headers={connectedassetheaders} rows={connectedassetrows} />
    </div>
  );
}