// apps/admin/src/app/(admin)/page.tsx // D3RO Voice Admin CRM — Unified Dashboard Overview (Midnight Glass v2) import { Box, Typography, Button } from '@mui/material' import { fetchServerStats } from '@/lib/api-server' import { isSupabaseAdminConfigured } from '@/lib/supabase-admin' import { fetchSubscriptionRevenue, type SubscriptionRevenue } from '@/lib/subscription-metrics' import { C, FONT_SANS, FONT_MONO, panelSx, tableSx, statusBadgeSx } from '@/lib/console-theme' import { DoubleBezelCard, StatRing, TactileBadge } from '@d3ro/ui/components/ds' import Link from 'next/link' export default async function AdminOverviewPage(): Promise { const stats = await fetchServerStats() const nonOperationalNodes = stats.nodes.filter((node) => node.status !== 'operational') let revenue: SubscriptionRevenue | null = null if (isSupabaseAdminConfigured()) { try { revenue = await fetchSubscriptionRevenue() } catch { revenue = null } } const revenueCards = revenue ? [ { title: 'Annual Recurring Revenue', value: `$${revenue.arrUsd.toLocaleString()}`, subtext: 'Active subscriptions × 12 months', color: 'green' as const, badge: 'ARR', badgeColor: 'green' as const, }, { title: 'Monthly Recurring Revenue', value: `$${revenue.mrrUsd.toLocaleString()}`, subtext: `Pro ${revenue.tierBreakdown.pro.toLocaleString()} · Pro+ ${revenue.tierBreakdown.pro_plus.toLocaleString()}`, color: 'blue' as const, badge: 'MRR', badgeColor: 'blue' as const, }, { title: 'Active Subscriptions', value: revenue.activeCount.toLocaleString(), subtext: 'Supabase subscriptions with status = active', color: 'purple' as const, badge: 'BILLING', badgeColor: 'purple' as const, }, ] : [] const bentoCards = [ { title: 'Backend Uptime', value: `${Math.floor(stats.serverUptimeSeconds / 3600).toLocaleString()}h`, subtext: 'Measured by the active .NET API process', color: 'purple' as const, badge: 'RUNTIME', badgeColor: 'purple' as const, icon: ( ), }, { title: 'Active Admin Accounts Today', value: `${stats.activeUsersToday.toLocaleString()} Active`, subtext: `${stats.totalUsers.toLocaleString()} administrator accounts`, color: 'blue' as const, badge: 'AUTH', badgeColor: 'blue' as const, icon: ( ), }, { title: 'Total API Requests & Compute', value: `${stats.totalRequests.toLocaleString()}`, subtext: `Total Compute Cost: $${stats.totalCost.toFixed(4)}`, color: 'green' as const, badge: 'TELEMETRY', badgeColor: 'green' as const, icon: ( ), }, { title: 'Recorded Backend Errors', value: stats.errorCount.toLocaleString(), subtext: 'Persisted server error log entries', color: 'orange' as const, badge: 'ERROR LOG', badgeColor: 'orange' as const, icon: ( ), }, ] return ( <> {/* Header bar */} Unified Dashboard Overview BACKEND CONNECTED Backend runtime counters, error ledger, reported node health {/* Main Content Area */} {/* Revenue KPI Row */} {revenueCards.length > 0 && ( {revenueCards.map((card) => ( $ {card.badge} {card.title} {card.value} {card.subtext} ))} )} {/* Executive Bento Grid */} {bentoCards.map((card) => ( {card.icon} {card.badge} {card.title} {card.value} {card.subtext} ))} {/* Live System Nodes Grid */} System Nodes & Pipeline Topology {stats.nodes.length === 0 ? 'NODE TELEMETRY NOT REPORTED' : `${stats.nodes.length} REPORTED • ${nonOperationalNodes.length} NON-OPERATIONAL`} {stats.nodes.length === 0 ? 'UNAVAILABLE' : nonOperationalNodes.length === 0 ? 'ALL REPORTED OPERATIONAL' : 'ATTENTION REQUIRED'} {stats.nodes.length === 0 ? ( No node-health telemetry has been reported by the backend. ) : stats.nodes.map((node) => ( {node.name} {node.versionOrModel} Latency: {node.latencyMs}ms {node.uptimePercent}% · {node.status.toUpperCase()} ))} {/* Server Operational Telemetry Logs */} Operational Telemetry & Server Logs SERVER SNAPSHOT ID STATUS MESSAGE ENDPOINT TIMESTAMP {stats.recentErrors.length === 0 ? ( No backend errors have been recorded. ) : ( stats.recentErrors.map((err) => ( #{err.id} {err.errorType} {err.message} {err.endpoint || '-'} {new Date(err.createdAt).toLocaleString()} )) )} ) }