import clsx from 'clsx'; import { fmt, fmtPct } from '../utils/format.js'; const ZONE_COLORS = { CRITICAL: 'var(--zone-critical)', UNDERFUNDED: 'var(--zone-under)', PROFIT: 'var(--zone-profit)', WASTAGE: 'var(--zone-wastage)', ZERO: 'var(--text-mute)', }; function zoneFor(allocation, t) { if (allocation === 0) return 'ZERO'; if (allocation < t.critical) return 'CRITICAL'; if (allocation < t.demand) return 'UNDERFUNDED'; if (allocation <= t.surplus) return 'PROFIT'; return 'WASTAGE'; } export default function SectorCard({ sector, allocation, revenue, revenueFactor, consumption, thresholds, eventMultiplier, isFailureRound = false, isFailingSector = false, }) { const zone = zoneFor(allocation, thresholds); const zoneColor = ZONE_COLORS[zone]; const max = Math.max(thresholds.wastage * 1.2, allocation * 1.05, 1); const allocPct = (allocation / max) * 100; const critPct = (thresholds.critical / max) * 100; const demandPct = (thresholds.demand / max) * 100; const surplusPct = (thresholds.surplus / max) * 100; const wastagePct = (thresholds.wastage / max) * 100; const ratio = thresholds.demand > 0 ? allocation / thresholds.demand : 0; return (
{sector.full_name} {' '}{eventMultiplier !== 1 ? `event ×${eventMultiplier.toFixed(2)}` : ''}
{isFailingSector ? ( FAILED · {fmtPct(ratio)} ) : isFailureRound ? ( {zone} · no rev ) : ( {zone} )}
crit
demand
surplus
wastage
Allocated {fmt(allocation)}
Revenue {fmt(revenue)}
RF × Prod {revenueFactor.toFixed(2)}
Demand {fmt(thresholds.demand)}
Consumed {fmt(consumption)}
% of demand {fmtPct(ratio)}
); }