"use client"; import { useEffect, useState } from "react"; import Link from "next/link"; interface Pkg { id: string; name: string; price: string; features: string; isActive: boolean; } interface Tenant { id: string; name: string; licenseNumber?: string; packageId?: string; isActive: boolean; createdAt: string; } import { useDictionary } from "@/lib/dictionary"; import { useOmni } from "@/components/OmniSyncProvider"; export default function BillingManagementPage() { const { t } = useDictionary(); const { currency, setCurrency, formatCurrency, locale, setLocale, theme, setTheme } = useOmni(); const [packages, setPackages] = useState([]); const [tenants, setTenants] = useState([]); const [loading, setLoading] = useState(true); const [stats, setStats] = useState({ totalRevenue: 150000000, activeTenants: 0, growth: "+12.5%" }); useEffect(() => { (async () => { try { const [pkgResp, eyeResp] = await Promise.all([ fetch("/api/superadmin/packages"), fetch("/api/superadmin/supreme-dashboard") ]); const pkgData = await pkgResp.json(); const eyeData = await eyeResp.json(); setPackages(pkgData.packages || []); setTenants(eyeData.matrix || []); // Calculate stats const activeCount = (eyeData.matrix || []).filter((t: Tenant) => t.isActive).length; setStats(prev => ({ ...prev, activeTenants: activeCount })); } catch (_e) { console.error("Failed to load billing data"); } finally { setLoading(false); } })(); }, []); const handleKillSwitch = async (id: string, name: string) => { if (!confirm(`ACTIVATE KILL-SWITCH: Deactivate [${name}] immediately?`)) return; try { const res = await fetch('/api/superadmin/tenants', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ action: 'update', id, isActive: false }) }); if (res.ok) { setTenants(prev => prev.map(t => t.id === id ? { ...t, isActive: false } : t)); } } catch (_e) {} }; const handleReactivate = async (id: string) => { try { const res = await fetch('/api/superadmin/tenants', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ action: 'update', id, isActive: true }) }); if (res.ok) { setTenants(prev => prev.map(t => t.id === id ? { ...t, isActive: true } : t)); } } catch (_e) {} }; if (loading) return
SYNCHRONIZING BILLING MATRIX...
; return (
{/* BACKGROUND DECORATION */}
{/* HEADER */}

XCU {t('Billing.title')}

Quantum Revenue & Subscription Orchestration Node.

{/* SETTINGS MATRIX */}
{t('Common.home')}
{/* STATS GRID */}
{[ { label: "ESTIMATED REVENUE", value: formatCurrency(stats.totalRevenue), color: "text-emerald-400", sub: "Calculated Real-time" }, { label: "ACTIVE TENANTS", value: stats.activeTenants.toString(), color: "text-blue-400", sub: stats.growth + " this month" }, { label: "SYSTEM UPTIME", value: "99.999%", color: "text-purple-400", sub: "0ms Latency Logic" } ].map((s, i) => (
{s.label}
{s.value}
{s.sub}
))}
{/* ACTIVE PACKAGES */}

LIVE SUBSCRIPTION PLANS

{packages.map(pkg => { const numericPrice = parseInt(pkg.price.replace(/[^0-9]/g, '') || '0'); return (

{pkg.name}

{numericPrice === 0 ? 'PARTNER FREE' : formatCurrency(numericPrice)}
{JSON.parse(pkg.features || '[]').slice(0, 3).map((f: string, idx: number) => (
{f.replace(/\./g, ' ').split(' ').slice(-1)[0].toUpperCase()}
))} {JSON.parse(pkg.features || '[]').length > 3 && (
+{JSON.parse(pkg.features || '[]').length - 3} MORE CAPABILITIES
)}
Status: PROVISIONED
)})}
{/* TENANT TABLE */}

TENANT SUBSCRIPTION REGISTRY

{tenants.map(t => ( ))}
Identity License Number Provision Date Status Emergency Control
{t.name}
UID: {t.id.substring(0, 8)}...
{t.licenseNumber || "N/A"} {new Date(t.createdAt).toLocaleDateString()} {t.isActive ? (
ACTIVE
) : (
SUSPENDED
)}
{t.isActive ? ( ) : ( )}
{/* FOOTER WATERMARK */}
JUMPA.ID ULTRA BILLING SYSTEM V2.4
ENCRYPTED QUANTUM HANDSHAKE: SUCCESS
); }