/* global window, React */ // ============================================================ // Today — situational snapshot across all DCs the TP covers. // This is the morning-ritual tab: less interactive than Tactical, // more readout. Sections: // 1. Hero header (date / time / one-liner) // 2. Day KPI strip (6 KPIs) // 3. Per-DC pulse cards (1 per DC in scope) // 4. Two-col row: Wave health timeline + Today vs Yesterday variance // 5. On the clock — trips delivering in the next 8h // 6. Live agent decision stream // ============================================================ const { useState: useTodayState, useMemo: useTodayMemo } = React; function TodayKpi({ label, value, sub, kind }) { return (
{label}
{value}
{sub &&
{sub}
}
); } // Tiny sparkline used in DC pulse cards function Sparkline({ values, width = 100, height = 24, color = 'var(--ink-2)' }) { if (!values || values.length === 0) return null; const min = Math.min(...values); const max = Math.max(...values); const range = max - min || 1; const pad = 2; const dx = (width - pad * 2) / (values.length - 1); const pts = values.map((v, i) => { const x = pad + i * dx; const y = pad + (1 - (v - min) / range) * (height - pad * 2); return [x, y]; }); const d = pts.map(([x, y], i) => (i === 0 ? `M ${x} ${y}` : `L ${x} ${y}`)).join(' '); const last = pts[pts.length - 1]; return ( ); } // ---------- Per-DC pulse card ---------- function DcPulseCard({ dc, onOpenDc }) { const tierColor = dc.pulseTier === 'green' ? 'var(--green)' : dc.pulseTier === 'amber' ? 'var(--amber)' : 'var(--red)'; return (
{dc.label} {dc.primary && PRIMARY}
{dc.region}
{dc.tripsToday}
trips today
{dc.inflight} in-flight {dc.delivered} delivered {dc.planned} planned {dc.held > 0 && {dc.held} held}
0 ? 'dc-pulse__risk--red' : ''}`}> {dc.otif} OTIF risk
0 ? 'dc-pulse__risk--amber' : ''}`}> {dc.lowUtil} low util
0 ? 'dc-pulse__risk--red' : ''}`}> {dc.overweight} overweight
avg util {dc.avgUtil}%
STATUS {dc.pulseLabel}
); } // ---------- Wave health timeline ---------- function WaveHealth({ waves }) { return (
Wave-run health · last 6 waves
One per hour · current wave (W7) is live
{waves.map(w => { const isLive = w.status === 'live'; return (
{w.wave}
{isLive ? ( live ) : ( <> {w.autoN}auto 5 ? 'wh-wave__num--amber' : ''}`}>{w.reviewN}review )}
{!isLive &&
{(w.durationS / 60).toFixed(1)}m
}
); })}
); } // ---------- Today vs Yesterday variance ---------- function VariancePanel({ variance }) { return (
Today vs yesterday
What's different · what to watch
{variance.map(v => (
{v.dir === 'up' ? '↑' : v.dir === 'down' ? '↓' : '→'}
{v.label} {v.today} vs {v.yesterday}
{v.sub}
))}
); } // ---------- On the clock table ---------- function OnTheClock({ items, scope, onOpenTrip }) { const filtered = scope === 'all' ? items : items.filter(i => i.dc === scope); return (
On the clock · next 8h
{filtered.length} delivery windows · sorted by urgency
Trip DC Destination Customer Deadline Hrs out Status Agent note
{filtered.map(it => (
onOpenTrip(it.tripId)}> {it.tripId} {it.dc.toUpperCase()} {it.dest} {it.customer} {it.deadline} {it.hrsToDeadline}h {it.status} TP {it.note}
))} {filtered.length === 0 && (
No deliveries in scope.
)}
); } // ---------- Agent decision stream ---------- function AgentStream({ items, scope }) { const filtered = scope === 'all' ? items : items.filter(i => i.dc === scope); const kindKind = (k) => k.startsWith('auto') ? 'green' : k === 'notified' ? 'blue' : k === 'awaiting TP' ? 'amber' : 'grey'; return (
Agent stream · last hour
live · {filtered.length} decisions
{filtered.map((it, i) => (
{it.ts} {it.dc.toUpperCase()} {it.tripId} {it.kind} {it.text} {it.dollars && +${it.dollars}}
))} {filtered.length === 0 &&
No agent activity in this scope.
}
); } // ---------- Main ---------- function TodayTab({ dcScope, onSwitchToTactical }) { const T = window.TODAY; const dcs = window.DCS; const scope = dcScope || 'all'; // Pulse cards — filter to DCs in scope const visiblePulse = scope === 'all' ? T.pulse : T.pulse.filter(p => p.dc === scope); // Aggregate KPIs across visible DCs const agg = useTodayMemo(() => { const ps = visiblePulse; return { tripsToday: ps.reduce((a, p) => a + p.tripsToday, 0), inflight: ps.reduce((a, p) => a + p.inflight, 0), delivered: ps.reduce((a, p) => a + p.delivered, 0), planned: ps.reduce((a, p) => a + p.planned, 0), otif: ps.reduce((a, p) => a + p.otif, 0), held: ps.reduce((a, p) => a + p.held, 0), }; }, [visiblePulse]); const handleOpenTrip = (tripId) => { onSwitchToTactical && onSwitchToTactical({ tripId }); }; const handleOpenDc = (dcId) => { onSwitchToTactical && onSwitchToTactical({ dc: dcId }); }; const scopeLabel = scope === 'all' ? `${dcs.length} DCs` : dcs.find(d => d.id === scope)?.name + ' DC'; return (
{/* Hero header */}
TODAY · {T.timeNow}
{T.date}
{agg.tripsToday} trips delivering today across {scopeLabel}. {agg.otif} at OTIF risk · {agg.inflight} in-flight · est. day cost ${T.dayKpis.estDayCost.toLocaleString()} {T.dayKpis.estDayCost > T.dayKpis.lastDayCost ? '+' : '−'}${Math.abs(T.dayKpis.estDayCost - T.dayKpis.lastDayCost).toLocaleString()} vs yesterday
{/* KPI strip */}
{/* Per-DC pulse */}
DC pulse {scope !== 'all' && '· (others hidden)'}
Live per-DC snapshot · click any DC to drill into Tactical
{visiblePulse.map(p => ( ))}
{/* Two-col: Wave health + Variance */}
{/* On the clock */}
{/* Agent stream */}
); } Object.assign(window, { TodayTab });