import React from 'react';
import { BarChart2, Zap } from "lucide-react";
import Button from "@/components/common/button";
import { Card } from '@/components/common/cardWrapper';
import Table from '@/components/common/dataTable';
import { energyUtilityHeaders, energyUtilityRows } from '@/constants/tabledata';
import InfoBanner from '@/components/common/infoBanner';

export default function EnergyUtilityPortal() {
  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-[11px] font-semibold tracking-widest text-[#4e6178] uppercase font-mono">
            <span className="text-emerald-400 font-bold">APPLE ONE — HQ TOWER</span>
            <span>•</span>
            <span>IOT</span>
            <span>•</span>
            <span>ENERGY & UTILITIES</span>
          </div>
          <h1 className="text-2xl font-bold text-white tracking-tight mt-1">
            Energy & utilities telemetry
          </h1>
          <p className="text-sm text-[#7f93ac] mt-2 max-w-xl leading-relaxed">
            Live smart-meter streams for power, water and gas — the same spine that feeds the Energy module and ESG reporting.
          </p>
        </div>

        {/* --- HEADER BUTTONS --- */}
        <div className="flex items-center gap-3 self-start md:mt-2">
          <Button className="bg-[#0e1c2e] hover:bg-slate-800 text-slate-200 border border-[#162942] 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-400" />
            <span>Export readings</span>
          </Button>

          <Button className="bg-[#10b981] hover:bg-emerald-400 text-slate-950 font-bold text-xs px-4 py-2 rounded-lg flex items-center gap-2 transition-colors shadow-lg">
            <Zap className="w-4 h-4 fill-slate-950 text-slate-950" />
            <span>Open Energy module</span>
          </Button>
        </div>
      </div>

      {/* --- STAT CARDS (WITH PROGRESS LINES) --- */}
      <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 mb-6">
        
        {/* Card 1: LIVE BUILDING LOAD */}
        <Card className="p-4 min-h-[120px] flex flex-col justify-between">
          <div>
            <span className="text-[10px] font-bold text-[#5c738e] tracking-wider uppercase font-mono">
              LIVE BUILDING LOAD
            </span>
            <div className="text-3xl font-extrabold text-white mt-1">386 kW</div>
            <p className="text-xs text-[#5c738e] mt-1">peak today 512 kW</p>
          </div>
          <div className="w-full bg-[#122339] h-1 rounded-full mt-4 overflow-hidden">
            <div className="bg-emerald-400  rounded-full" style={{ width: '70%' }}></div>
          </div>
        </Card>

        {/* Card 2: ENERGY TODAY (Active highlighted border) */}
        <Card className="p-4 min-h-[120px] flex flex-col justify-between border-2 border-emerald-500/80 bg-emerald-950/10">
          <div>
            <span className="text-[10px] font-bold text-[#5c738e] tracking-wider uppercase font-mono">
              ENERGY TODAY
            </span>
            <div className="text-3xl font-extrabold text-white mt-1">3,120 kWh</div>
            <p className="text-xs text-[#5c738e] mt-1">-4% vs yesterday</p>
          </div>
          <div className="w-full bg-[#122339] h-1 rounded-full mt-4 overflow-hidden">
            <div className="bg-emerald-400  rounded-full" style={{ width: '65%' }}></div>
          </div>
        </Card>

        {/* Card 3: WATER TODAY */}
        <Card className="p-4 min-h-[120px] flex flex-col justify-between">
          <div>
            <span className="text-[10px] font-bold text-[#5c738e] tracking-wider uppercase font-mono">
              WATER TODAY
            </span>
            <div className="text-3xl font-extrabold text-white mt-1">38.4 kL</div>
            <p className="text-xs text-[#5c738e] mt-1">municipal + borewell</p>
          </div>
          <div className="w-full bg-[#122339] h-1 rounded-full mt-4 overflow-hidden">
            <div className="bg-blue-500 h-full rounded-full" style={{ width: '50%' }}></div>
          </div>
        </Card>

        {/* Card 4: METERS ONLINE */}
        <Card className="p-4 min-h-[120px] flex flex-col justify-between">
          <div>
            <span className="text-[10px] font-bold text-[#5c738e] tracking-wider uppercase font-mono">
              METERS ONLINE
            </span>
            <div className="text-3xl font-extrabold text-white mt-1">4 / 6</div>
            <p className="text-xs text-[#5c738e] mt-1">1 gas meter offline</p>
          </div>
          <div className="w-full bg-[#122339] h-1 rounded-full mt-4 overflow-hidden">
            <div className="bg-amber-400 h-full rounded-full" style={{ width: '67%' }}></div>
          </div>
        </Card>

      </div>

      {/* --- TELEMETRY & BREAKDOWN SECTION --- */}
      <div className="grid grid-cols-1 lg:grid-cols-12 gap-6">
        
        {/* Left Side: Smart Meters Table */}
        <Card className="lg:col-span-7 p-6 flex flex-col justify-between">
          <div>
            <div className="mb-6">
              <h2 className="text-lg font-bold text-white">Smart meters</h2>
              <p className="text-xs text-[#5c738e] font-mono mt-0.5">auto-polled</p>
            </div>

            <Table headers={energyUtilityHeaders} rows={energyUtilityRows} />
          </div>
        </Card>

        {/* Right Side: Load by end use — live */}
        <Card className="lg:col-span-5 p-4 flex flex-col justify-between">
          <div>
            <div className="mb-6">
              <h2 className="text-lg font-bold text-white">Load by end use — live</h2>
              <p className="text-xs text-[#5c738e] font-mono mt-0.5">% of 386 kW</p>
            </div>

            {/* Load Breakdown Bars */}
            <div className="space-y-5">
              
              {/* HVAC Plant */}
              <div>
                <div className="flex justify-between text-xs font-bold mb-1.5">
                  <span className="text-slate-100">HVAC plant</span>
                  <span className="text-[#5c738e] font-mono">44%</span>
                </div>
                <div className="w-full bg-[#122339] h-2 rounded-full overflow-hidden">
                  <div className="bg-blue-500 h-full rounded-full" style={{ width: '44%' }}></div>
                </div>
              </div>

              {/* Lighting & small power */}
              <div>
                <div className="flex justify-between text-xs font-bold mb-1.5">
                  <span className="text-slate-100">Lighting & small power</span>
                  <span className="text-[#5c738e] font-mono">23%</span>
                </div>
                <div className="w-full bg-[#122339] h-2 rounded-full overflow-hidden">
                  <div className="bg-emerald-400 rounded-full" style={{ width: '23%' }}></div>
                </div>
              </div>

              {/* Lifts & pumps */}
              <div>
                <div className="flex justify-between text-xs font-bold mb-1.5">
                  <span className="text-slate-100">Lifts & pumps</span>
                  <span className="text-[#5c738e] font-mono">12%</span>
                </div>
                <div className="w-full bg-[#122339] h-2 rounded-full overflow-hidden">
                  <div className="bg-amber-400 h-full rounded-full" style={{ width: '12%' }}></div>
                </div>
              </div>

              {/* Data / UPS */}
              <div>
                <div className="flex justify-between text-xs font-bold mb-1.5">
                  <span className="text-slate-100">Data / UPS</span>
                  <span className="text-[#5c738e] font-mono">11%</span>
                </div>
                <div className="w-full bg-[#122339] h-2 rounded-full overflow-hidden">
                  <div className="bg-emerald-400  rounded-full" style={{ width: '11%' }}></div>
                </div>
              </div>

              {/* Others */}
              <div>
                <div className="flex justify-between text-xs font-bold mb-1.5">
                  <span className="text-slate-100">Others</span>
                  <span className="text-[#5c738e] font-mono">10%</span>
                </div>
                <div className="w-full bg-[#122339] h-2 rounded-full overflow-hidden">
                  <div className="bg-slate-500  rounded-full" style={{ width: '10%' }}></div>
                </div>
              </div>

            </div>
          </div>
<InfoBanner boldText='Anomaly watch:' normalText='lighting load after 22:00 is 9% above baseline on Block 1 · L3 — an automation rule can raise a Help Desk ticket automatically (see Alarms & Rules).
          '/>
         
        </Card>

      </div>

    </div>
  );
}