import {
  Database,
  FileText,
  Activity,
  AlertTriangle,
  Plus
} from "lucide-react";

import InfoBanner from "@/components/common/infoBanner";
import Button from "@/components/common/button";
import StatCard from "@/components/common/dashStatCard";
import { Card } from '@/components/common/cardWrapper';
import { CardHeader } from '@/components/common/cardHeader';
import { approvalQueueData, categoryData } from "@/constants/constant";
import Table from "@/components/common/dataTable";
import { budgetPerformanceRows } from "@/constants/tabledata";
import { budgetPerformanceHeaders } from "@/constants/tabledata";



export default function BudgetPortal() {
  return (
    <div className="my-15 text-slate-100 font-sans">
      {/* --- HEADER SECTION WITH BUTTONS --- */}
      <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">FINANCE</span>
            <span className="text-gray-600">•</span>
            <span className="text-gray-400">O&M BUDGET</span>
          </div>

          <h1 className="text-2xl font-bold text-white tracking-tight mt-2">
            O&M budget management
          </h1>

          <p className="text-sm font-medium text-slate-400 mt-2 max-w-xl leading-relaxed">
            Multi-dimensional budgets by site, department and asset — planned vs actual, variance, approvals and overrun alerts.
          </p>
        </div>

        {/* --- HEADER BUTTONS --- */}
        <div className="flex items-center gap-2.5 self-start md:mt-6">
          <Button className="bg-[#0b1727] hover:bg-slate-800/60 text-slate-200 border border-slate-800 text-xs px-4 py-2 rounded-lg font-semibold transition-colors">
            <span>Export</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-1.5 transition-colors">
            <Plus className="w-4 h-4 stroke-[3]" />
            <span>New budget</span>
          </Button>
        </div>
      </div>

      {/* --- STAT CARDS --- */}
      <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 mb-6">
        {/* Annual budget */}
        <StatCard
          variant="icon"
          title="Annual budget"
          value="₹1.91 Cr"
          icon={Database}
          badgeText="FY 2026"
          badgeClassName="text-slate-400 lowercase font-mono"
          iconContainerClassName="bg-blue-950/40 border-blue-800/30 text-blue-400"
        />

        {/* Spent YTD */}
        <StatCard
          variant="icon"
          title="Spent YTD"
          value="₹1.42 Cr"
          icon={FileText}
          badgeText="74% used"
          badgeClassName="text-emerald-400 lowercase font-mono"
          iconContainerClassName="bg-emerald-950/40 border-emerald-800/30 text-emerald-400"
        />

        {/* Remaining */}
        <StatCard
          variant="icon"
          title="Remaining"
          value="₹49.0 L"
          icon={Activity}
          badgeText="26% left"
          badgeClassName="text-slate-400 lowercase font-mono"
          iconContainerClassName="bg-amber-950/40 border-amber-800/30 text-amber-400"
        />

        {/* Overrun lines */}
        <StatCard
          variant="icon"
          title="Overrun lines"
          value="1"
          icon={AlertTriangle}
          badgeText="review"
          badgeClassName="text-rose-400 lowercase font-mono"
          iconContainerClassName="bg-rose-950/40 border-rose-900/30 text-rose-400"
        />
      </div>

      {/* --- BUDGET DETAILS & APPROVAL QUEUE SECTION --- */}
      <div className="grid grid-cols-2 gap-3 mb-8">
        {/* Planned vs Actual Table (Left 2 Columns) */}
          <div className=" border border-slate-800/80 rounded-lg ">
                  <div className="flex items-center justify-between
                   px-4 py-4 border-b border-slate-800/80">
                    <h2 className="text-base font-semibold text-white">
                      Planned vs actual·by category</h2>
                    
                  </div>
        
                  {/* Corrected column layout and removed horizontal scrollbar to align with the right UI. */}
                  <Table headers={budgetPerformanceHeaders} rows={budgetPerformanceRows} />
                </div>
         
        
          
        

        {/* Approval Queue Panel (Right 1 Column) */}
        <Card className="justify-start">
          <CardHeader title="Approval queue" subtitle="multi-level" />

          <div className="divide-y divide-[#162942]/60 mt-1">
            {approvalQueueData.map((item) => (
              <div key={item.id} className="py-3.5 flex items-center justify-between gap-3">
                <div>
                  <h4 className="text-xs font-semibold text-white leading-snug">
                    {item.title}
                  </h4>
                  <p className="text-[11px] font-mono text-slate-500 mt-1">
                    {item.id} · {item.meta}
                  </p>
                </div>

                {item.status === "pending" ? (
                  <Button className="bg-[#12233a] hover:bg-[#1a3252] border border-[#1d3554] text-slate-200 text-xs font-semibold px-3 py-1 rounded transition-colors whitespace-nowrap">
                    Approve
                  </Button>
                ) : (
                  <span className="flex items-center gap-1.5 bg-emerald-950/40 border border-emerald-800/30 text-emerald-400 text-[10px] font-mono font-bold px-2.5 py-1 rounded-full whitespace-nowrap">
                    <span className="w-1.5 h-1.5 rounded-full bg-emerald-400" />
                    COMPLETED
                  </span>
                )}
              </div>
            ))}
          </div>
        </Card>
      </div>

      {/* Info Banner */}
      <div className="my-8">
        <InfoBanner
          boldText="Utilization %"
          normalText=" per category = Actual ÷ Planned × 100 (the bar turns amber past 90%, red on overrun); categories & types are configured in Master Data → Finance. Integration: budget lines link to work orders, purchase orders and vendor invoices — actuals post back automatically and overruns raise an alert to the approver."
        />
      </div>
    </div>
  );
}