/* ── Status page ── */ const StatusPage = (() => { async function init(container) { container.innerHTML = `
Loading...
`; document.getElementById('status-refresh').onclick = () => load(container); load(container); } async function load(container) { const body = document.getElementById('status-body'); try { const res = await fetch('/api/status'); if (!res.ok) throw new Error(`HTTP ${res.status}`); const d = await res.json(); body.innerHTML = render(d); } catch (e) { body.innerHTML = `

Failed to load status: ${e.message}

`; } } function fmtUptime(seconds) { const d = Math.floor(seconds / 86400); const h = Math.floor((seconds % 86400) / 3600); const m = Math.floor((seconds % 3600) / 60); const s = seconds % 60; if (d > 0) return `${d}d ${h}h ${m}m`; if (h > 0) return `${h}h ${m}m ${s}s`; if (m > 0) return `${m}m ${s}s`; return `${s}s`; } function fmtBytes(bytes) { if (bytes === 0) return '0 B'; if (bytes < 1024) return `${bytes} B`; if (bytes < 1048576) return `${(bytes / 1024).toFixed(1)} KB`; return `${(bytes / 1048576).toFixed(2)} MB`; } function row(label, value, note = '') { return `
${label} ${value}${note ? `${note}` : ''}
`; } function render(d) { const dbOk = d.database.status === 'connected'; return `
Application
${row('Version', `v${d.app.version}`)} ${row('Environment', d.app.environment)} ${row('Uptime', fmtUptime(d.app.uptime_seconds))}
Runtime
${row('Node.js', d.runtime.node_version)} ${row('Platform', `${d.runtime.platform} / ${d.runtime.arch}`)} ${row('Memory', `${d.runtime.memory_mb} MB`)}
Database
${row('Status', dbOk ? 'Connected' : 'Error')} ${row('Size', fmtBytes(d.database.size_bytes))} ${row('File', `${d.database.path}`)}
Statistics
${row('Active Bills', d.stats.active_bills)} ${row('Total Payments', d.stats.total_payments)} ${row('Users', d.stats.users)} ${row('Active Sessions', d.stats.active_sessions)}
`; } return { init }; })();