// My Estimates (ADR-0013): list saved estimates newest-first; reopen or discard. import { listEstimates, deleteEstimate } from "./client.js"; 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 host = document.getElementById("estimates"); host.innerHTML = ""; const data = await listEstimates(); const estimates = data.estimates || []; document.getElementById("est-count").textContent = `${estimates.length} estimate${estimates.length === 1 ? "" : "s"}`; if (!estimates.length) { host.append( el(`
folder No saved estimates yet. Forge one →
`), ); return; } const table = el(`
RefJobTotal
`); const tbody = table.querySelector("tbody"); for (const e of estimates) { const tr = el(` #${e.id} ${e.job_title} ${money(e.total)} `); tr.querySelector("[data-del]").addEventListener("click", async () => { await deleteEstimate(e.id); load(); }); tbody.append(tr); } host.append(table); } load();