import { useStore } from '../store' // batch state -> [label, colour token, pill colour] export const STATES: Record = { completed: ['Completed', 'var(--ok)', 'bg-ok'], inprogress: ['In progress', 'var(--warn)', 'bg-warn'], notcompleted: ['Not completed', 'var(--bad)', 'bg-bad'], cleared: ['Cleared', 'var(--muted)', 'bg-muted'], } function Kpi({ label, n, colour, live }: { label: string; n: number; colour: string; live?: boolean }) { return (
{n}
{label}
) } export function Overview() { const { batches } = useStore() const count = Object.fromEntries(Object.keys(STATES).map((k) => [k, batches.filter((b) => b.state === k).length])) const total = Object.values(count).reduce((a, x) => a + x, 0) let acc = 0 const stops = Object.keys(STATES).flatMap((k) => { if (!count[k]) return [] const from = (acc / total) * 100 acc += count[k] return [`${STATES[k][1]} ${from}% ${(acc / total) * 100}%`] }) return (
0} />
Batch status split
`${STATES[k][0]} ${count[k]}`).join(', ') : 'no batches yet')} style={{ background: total ? `conic-gradient(${stops.join(',')})` : 'conic-gradient(var(--border) 0 100%)' }}>
{batches.length}
batches
    {Object.keys(STATES).map((k) => (
  • {STATES[k][0]} · {count[k]}
  • ))}
Recent batches
{batches.length === 0 &&
No batches yet
} {batches.slice(0, 6).map((b) => { const s = STATES[b.state] ?? [b.state, '', 'bg-warn'] return (
#{b.batch_id} · {b.date} {s[0]}
) })}
) }