// ─────────────────────────────────────────────────────────── // Huio Control Panel — Dashboard View (cp-dashboard-view.jsx) // ─────────────────────────────────────────────────────────── if (!window.CP_STYLES) throw new Error('[cp-dashboard-view] window.CP_STYLES not loaded'); function renderDashboard({ lang = 'vi', t: rawT, appStyles: rawAppStyles, users: rawUsers = [], groups: rawGroups = [], logs: rawLogs = [], dbStats = {}, errorLogs: rawErrorLogs = [], isConnected = false, }) { const appStyles = rawAppStyles || window.CP_STYLES || {}; const t = typeof rawT === 'function' ? rawT : (k) => k; const users = Array.isArray(rawUsers) ? rawUsers : []; const groups = Array.isArray(rawGroups) ? rawGroups : []; const logs = Array.isArray(rawLogs) ? rawLogs : []; const errorLogs = Array.isArray(rawErrorLogs) ? rawErrorLogs : []; const vndShort = window.vndShort || ((amount) => { if (amount === undefined || amount === null) return "0 ₫"; if (amount >= 1e9) return (amount / 1e9).toFixed(1) + "B ₫"; if (amount >= 1e6) return (amount / 1e6).toFixed(1) + "M ₫"; if (amount >= 1e3) return (amount / 1e3).toFixed(0) + "k ₫"; return amount + " ₫"; }); const totalDbRows = Object.values(dbStats || {}).reduce((a, b) => Number(a || 0) + Number(b || 0), 0); const errors24h = errorLogs.filter(e => new Date(e.created_at || Date.now()) > new Date(Date.now() - 24 * 3600 * 1000)).length; return (

{t('dashboard.welcome')}

{t('dashboard.sub')}

{/* Telemetry Metrics Grid */}
u.plan !== 'free').length} iconKind="users" /> acc + curr.volume, 0))} iconKind="money" />
{/* Interactive Cashflow Area/Line Chart */} {/* Split layout: System health & activity logging */}
{/* Left Column: Recent Logs */}

{t('dashboard.activity.title')}

{logs.slice(0, 10).map(log => (
{log.time} {log.type.toUpperCase()} {log.text}
))}
{/* Right Column: Dynamic Health metrics */}

{t('dashboard.syshealth')}

{t('dashboard.syshealth.api')} {isConnected ? 'Live (OK)' : 'Demo'}
{t('dashboard.syshealth.db')} {totalDbRows > 0 ? `${totalDbRows.toLocaleString()} rows` : 'Active'}
{t('dashboard.syshealth.errors')} {errors24h} (24h)
0 ? `${Math.min(100, errors24h * 10)}%` : '0%', background: 'var(--hu-rust)' }} />
); } window.CpDashboardView = { renderDashboard, };