export function renderStorage(state) { const storage = state.storage || {}; const grid = document.getElementById("storage-grid"); if (!grid) return; const root = storage.root || storage.disks?.[0] || null; const disks = storage.disks || []; const rootPct = root?.usage_percent ?? 0; const rootTone = pickTone(rootPct); const warningCount = disks.filter((disk) => between(disk.usage_percent, 70, 85)).length; const criticalCount = disks.filter((disk) => (disk.usage_percent ?? 0) > 85).length; const highest = disks.length ? disks.reduce((current, disk) => ((disk.usage_percent ?? 0) > (current.usage_percent ?? 0) ? disk : current), disks[0]) : null; const matrixPill = criticalCount > 0 ? "pill-offline" : warningCount > 0 ? "pill-degraded" : "pill-online"; const strip = disks.length ? disks.slice(0, 4).map((disk) => { const pct = disk.usage_percent ?? 0; return `${disk.name || disk.mount} ${pct.toFixed(0)}%`; }).join("") : 'No disk data'; grid.innerHTML = `
ROOT STORAGE
${(root?.status || "stable").toUpperCase()}
${root ? `${rootPct.toFixed(1)}%` : "\u2014"}
Usage
${root ? fmtNum(root.used_gb) : "\u2014"}
Used GB
${root ? fmtNum(root.free_gb) : "\u2014"}
Free GB
${root?.mount || "/"}${root ? `${rootPct.toFixed(1)}%` : "0%"}
DISK MATRIX
${disks.length}
${disks.length || "\u2014"}
Volumes
${warningCount}
Warning
${criticalCount}
Critical
${highest ? `${(highest.usage_percent ?? 0).toFixed(0)}%` : "\u2014"}
Peak
`; } function fmtNum(value) { return value == null ? "\u2014" : Number(value).toFixed(1); } function between(value, min, max) { const num = value ?? 0; return num > min && num <= max; } function pickTone(pct) { if (pct > 85) return "danger"; if (pct > 70) return "warn"; return ""; } function pickColor(pct) { if (pct > 85) return "var(--red)"; if (pct > 70) return "var(--yellow)"; return "var(--teal-bright)"; } function statusPill(status) { if (status === "critical") return "pill-offline"; if (status === "warning") return "pill-degraded"; return "pill-online"; }