// Tiny primitive components. const fmtTs = (t, opt = {}) => { const d = new Date(t); const pad = n => String(n).padStart(2, '0'); if (opt.short) return `${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`; if (opt.dateOnly) return `${d.getFullYear()}-${pad(d.getMonth()+1)}-${pad(d.getDate())}`; return `${d.getFullYear()}-${pad(d.getMonth()+1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`; }; const fmtNum = (n, dp = 2) => { if (n == null || isNaN(n)) return '—'; const sign = n < 0 ? '-' : ''; const a = Math.abs(n); return sign + a.toLocaleString('en-US', { minimumFractionDigits: dp, maximumFractionDigits: dp }); }; const fmtPct = (n, dp = 2) => `${n >= 0 ? '+' : ''}${(n*100).toFixed(dp)}%`; const since = (t) => { const d = Math.floor((Date.now() - t)/1000); if (d < 60) return `${d}s ago`; if (d < 3600) return `${Math.floor(d/60)}m ago`; if (d < 86400) return `${Math.floor(d/3600)}h ago`; return `${Math.floor(d/86400)}d ago`; }; // Pill — used everywhere for state/severity/mode tags. function Pill({ tone = 'ink', children, dot = false, className = '' }) { const tones = { ink: 'text-ink-1 bg-bg-2 border-line-1', pos: 'text-pos-0 bg-pos-2/30 border-pos-1/40', neg: 'text-neg-0 bg-neg-2/30 border-neg-1/40', amb: 'text-amb-0 bg-amb-1/15 border-amb-1/40', inf: 'text-inf-0 bg-inf-1/15 border-inf-1/40', live: 'text-neg-0 bg-neg-2/30 border-neg-1/50', paper: 'text-amb-0 bg-amb-1/15 border-amb-1/40', testnet:'text-inf-0 bg-inf-1/15 border-inf-1/40', }; return ( {dot && } {children} ); } // Card — every panel uses this. Hairline border, dim header. function Card({ title, sub, action, children, padded = true, className = '' }) { return (
{(title || action) && (
{title &&

{title}

} {sub && {sub}}
{action}
)}
{children}
); } // Stat — big number + label + delta. Used in dashboard top row. function Stat({ label, value, sub, delta, deltaTone, mono = true }) { return (
{label} {delta != null && ( {delta} )}
{value}
{sub && {sub}}
); } // Click-to-copy text. Used for client_order_ids etc. function Copy({ text, display, className = '' }) { const [done, setDone] = React.useState(false); return ( ); } // Tiny inline sparkline. function Sparkline({ data, w = 80, h = 22, color = '#7aaed8' }) { if (!data || !data.length) return null; const min = Math.min(...data), max = Math.max(...data); const span = max - min || 1; const step = w / (data.length - 1); const pts = data.map((v, i) => `${i*step},${h - ((v-min)/span)*h}`).join(' '); return ( ); } // Section divider with a small title — used inside dense panels. function Divider({ children, className = '' }) { return (
{children}
); } window.UI = { fmtTs, fmtNum, fmtPct, since, Pill, Card, Stat, Copy, Sparkline, Divider };