// Dashboard: render KPIs + recent jobs from the real memory read-model. const money = (n) => (n == null ? "—" : `$${Number(n).toFixed(2)}`); const el = (html) => { const t = document.createElement("template"); t.innerHTML = html.trim(); return t.content.firstElementChild; }; async function load() { const data = await (await fetch("/api/dashboard")).json(); document.getElementById("kpis").append( el(`

Jobs forged

${data.job_count}

on this device

`), el(`

Total estimated

${money(data.revenue_total)}

sum of finished estimates

`), el(`

Distinct items used

${data.top_items.length}

across past jobs

`), ); const recent = document.getElementById("recent"); if (!data.recent.length) { recent.append( el(`
description No jobs yet. Forge your first estimate →
`), ); } else { const rows = data.recent .map( (r) => ` ${r.transcript || "(no note)"} ${r.items} ${money(r.total)} `, ) .join(""); recent.append( el(`${rows}
Job noteItemsTotal
`), ); } const top = document.getElementById("top-items"); if (!data.top_items.length) { top.append(el(`

No items learned yet.

`)); } else { top.append( el( `
${data.top_items .map((i) => `${i}`) .join("")}
`, ), ); } } load();