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

import InfoBanner from "@/components/common/infoBanner";
import Button from "@/components/common/button";
import StatCard from "@/components/common/dashStatCard";
import Table from "@/components/common/dataTable";

const StatusBadge = ({
  text,
  color,
}: {
  text: string;
  color: string;
}) => (
  <span
    className={`inline-flex items-center gap-1 rounded-full px-3 py-1 text-[10px] font-semibold uppercase tracking-wider whitespace-nowrap ${color}`}
  >
    <span className="h-1.5 w-1.5 rounded-full bg-current" />
    {text}
  </span>
);

const ActionButton = ({ text }: { text: string }) => (
  <Button className="rounded-lg border border-slate-700/60 bg-[#16243a] px-3 py-1.5 text-sm font-semibold text-slate-300 hover:bg-slate-700 transition">
    {text}
  </Button>
);

const headers = [
  "Invoice",
  "Client",
  "Period",
  "Amount",
  "Raised",
  "Due",
  "Status",
  "",
];

const rows = [
  [
    <span className="font-semibold text-[#2EE6C5]">INV-9040</span>,
    <span className="font-semibold text-slate-100">Apple One Corp</span>,
    "Jun 2026",
    <span className="font-semibold">₹12.4 L</span>,
    <span className="font-mono">Jun 5, 2026</span>,
    <span className="font-mono">Jul 5, 2026</span>,
    <StatusBadge
      text="Paid"
      color="bg-emerald-500/15 text-emerald-400"
    />,
    <span className="text-slate-500">—</span>,
  ],

  [
    <span className="font-semibold text-[#2EE6C5]">INV-9041</span>,
    <span className="font-semibold text-slate-100">Novotel F&B</span>,
    "Jun 2026",
    <span className="font-semibold">₹8.6 L</span>,
    <span className="font-mono">Jun 9, 2026</span>,
    <span className="font-mono">Jul 9, 2026</span>,
    <StatusBadge
      text="Sent"
      color="bg-amber-500/15 text-amber-400"
    />,
    <ActionButton text="Mark paid" />,
  ],

  [
    <span className="font-semibold text-[#2EE6C5]">INV-9042</span>,
    <span className="font-semibold text-slate-100">SRM Estates</span>,
    "Jun 2026",
    <span className="font-semibold">₹4.3 L</span>,
    <span className="font-mono">Jun 13, 2026</span>,
    <span className="font-mono">Jul 13, 2026</span>,
    <StatusBadge
      text="Overdue"
      color="bg-red-500/15 text-red-400"
    />,
    <ActionButton text="Mark paid" />,
  ],

  [
    <span className="font-semibold text-[#2EE6C5]">INV-9043</span>,
    <span className="font-semibold text-slate-100">Local Mart</span>,
    "Jun 2026",
    <span className="font-semibold">₹21.0 L</span>,
    <span className="font-mono">Jun 17, 2026</span>,
    <span className="font-mono">Jul 17, 2026</span>,
    <StatusBadge
      text="Paid"
      color="bg-emerald-500/15 text-emerald-400"
    />,
    <span className="text-slate-500">—</span>,
  ],

  [
    <span className="font-semibold text-[#2EE6C5]">INV-9044</span>,
    <span className="font-semibold text-slate-100">Regus Spaces</span>,
    "Jun 2026",
    <span className="font-semibold">₹6.8 L</span>,
    <span className="font-mono">Jun 21, 2026</span>,
    <span className="font-mono">Jul 21, 2026</span>,
    <StatusBadge
      text="Draft"
      color="bg-slate-700/60 text-slate-400"
    />,
    <ActionButton text="Send" />,
  ],

  [
    <span className="font-semibold text-[#2EE6C5]">INV-9105</span>,
    <span className="font-semibold text-slate-100">Apple One Corp</span>,
    "Jun 2026",
    <span className="font-semibold">₹12.4 L</span>,
    <span className="font-mono">Jun 5, 2026</span>,
    <span className="font-mono">Jul 5, 2026</span>,
    <StatusBadge
      text="Sent"
      color="bg-amber-500/15 text-amber-400"
    />,
    <ActionButton text="Mark paid" />,
  ],

  [
    <span className="font-semibold text-[#2EE6C5]">INV-9106</span>,
    <span className="font-semibold text-slate-100">Novotel F&B</span>,
    "Jun 2026",
    <span className="font-semibold">₹8.6 L</span>,
    <span className="font-mono">Jun 9, 2026</span>,
    <span className="font-mono">Jul 9, 2026</span>,
    <StatusBadge
      text="Draft"
      color="bg-slate-700/60 text-slate-400"
    />,
    <ActionButton text="Send" />,
  ],

  [
    <span className="font-semibold text-[#2EE6C5]">INV-9107</span>,
    <span className="font-semibold text-slate-100">SRM Estates</span>,
    "Jun 2026",
    <span className="font-semibold">₹4.3 L</span>,
    <span className="font-mono">Jun 13, 2026</span>,
    <span className="font-mono">Jul 13, 2026</span>,
    <StatusBadge
      text="Draft"
      color="bg-slate-700/60 text-slate-400"
    />,
    <ActionButton text="Send" />,
  ],

  [
    <span className="font-semibold text-[#2EE6C5]">INV-9108</span>,
    <span className="font-semibold text-slate-100">Local Mart</span>,
    "Jun 2026",
    <span className="font-semibold">₹21.0 L</span>,
    <span className="font-mono">Jun 17, 2026</span>,
    <span className="font-mono">Jul 17, 2026</span>,
    <StatusBadge
      text="Paid"
      color="bg-emerald-500/15 text-emerald-400"
    />,
    <span className="text-slate-500">—</span>,
  ],
   [
    <span className="font-semibold text-[#2EE6C5]">INV-9107</span>,
    <span className="font-semibold text-slate-100">SRM Estates</span>,
    "Jun 2026",
    <span className="font-semibold">₹4.3 L</span>,
    <span className="font-mono">Jun 13, 2026</span>,
    <span className="font-mono">Jul 13, 2026</span>,
    <StatusBadge
      text="Draft"
      color="bg-slate-700/60 text-slate-400"
    />,
    <ActionButton text="Send" />,
  ],

  [
    <span className="font-semibold text-[#2EE6C5]">INV-9108</span>,
    <span className="font-semibold text-slate-100">Local Mart</span>,
    "Jun 2026",
    <span className="font-semibold">₹21.0 L</span>,
    <span className="font-mono">Jun 17, 2026</span>,
    <span className="font-mono">Jul 17, 2026</span>,
    <StatusBadge
      text="Paid"
      color="bg-emerald-500/15 text-emerald-400"
    />,
    <span className="text-slate-500">—</span>,
  ],
];
export default function CostInvoicePortal() {
  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-[10px] font-bold tracking-widest text-slate-500 uppercase font-mono">
            <span className="text-teal-400">Apple One — HQ Tower</span>
            <span>•</span>
            <span>FINANCE</span>
            <span>•</span>
            <span>COSTING & INVOICING</span>
          </div>

          <h1 className="text-2xl font-bold text-white tracking-tight mt-2">
            Client costing & auto-invoicing
          </h1>

          <p className="text-sm font-medium text-slate-400 mt-2 max-w-xl leading-relaxed">
            Client-wise costing setup, automatic project approval and invoice generation — fully native, no external dependency.
          </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-3.5 py-2 rounded-lg flex items-center gap-2 font-semibold transition-colors">
            <Sparkles className="w-4 h-4 text-slate-300" />
            <span>Costing rules</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>Generate invoice</span>
          </Button>
        </div>
      </div>

      {/* --- STAT CARDS --- */}
      <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 mb-6">
        {/* Billed */}
        <StatCard
          variant="icon"
          title="Billed"
          value="₹99.4 L"
          icon={FileText}
          badgeText="this month"
          badgeClassName="text-slate-400 lowercase font-mono"
          iconContainerClassName="bg-blue-950/40 border-blue-800/30 text-blue-400"
        />

        {/* Outstanding */}
        <StatCard
          variant="icon"
          title="Outstanding"
          value="₹45.0 L"
          icon={Database}
          badgeText="receivable"
          badgeClassName="text-amber-400 lowercase font-mono"
          iconContainerClassName="bg-amber-950/40 border-amber-800/30 text-amber-400"
        />

        {/* Overdue */}
        <StatCard
          variant="icon"
          title="Overdue"
          value="₹4.3 L"
          icon={AlertTriangle}
          badgeText="follow up"
          badgeClassName="text-rose-400 lowercase font-mono"
          iconContainerClassName="bg-rose-950/40 border-rose-900/30 text-rose-400"
          
        />

        {/* Collection rate */}
        <StatCard
          variant="icon"
          title="Collection rate"
          value="55%"
          icon={Activity}
          badgeText="MTD"
          badgeClassName="text-slate-400 font-mono uppercase"
          iconContainerClassName="bg-emerald-950/40 border-emerald-800/30 text-emerald-400"
        />
      </div>

<div className="mt-5">
    <Table headers={headers} rows={rows}/>
</div>
      {/* Info Banner */}
      <div className="my-8">
        <InfoBanner
          boldText="Auto-invoicing:"
          normalText=" completed work orders and AMC visits roll up into client costing by contract rate → invoice drafts are generated, approved, and dispatched without manual re-entry."
        />
      </div>
    </div>
  );
}