// Trends tab — five chart panels driven by /api/sleep-trends. const { thirdsPhases, phaseAvg, eventsToAnnotations, fmtBedtime } = window.HC_DATA; function Row({ label, value, color, theme }) { return (
{label} {value}
); } function PhaseStat({ name, color, sleep, hrv, ready, theme }) { const Card = window.HCCard; const p = theme.palette; return (
{name}
); } function ChartPanel({ title, unit, children, theme }) { const Card = window.HCCard; const p = theme.palette; return (
{title}
{unit}
{children}
); } function TrendsTab({ trends, series }) { const theme = window.HC_THEME.useHCTheme(); const p = theme.palette; const d = theme.density; const [range, setRange] = React.useState('full'); if (!trends || !series) { return (
loading trends…
); } const days = trends.days || []; // Expose date array so DateTicks can label the x-axis with real dates. window.HC_TREND_DATES = days.map((d) => d.day); const phases = thirdsPhases(days); const sleepPhase = (i) => phaseAvg(series.sleep, phases[i]); const hrvPhase = (i) => phaseAvg(series.hrv, phases[i]); const readyPhase = (i) => phaseAvg(series.ready, phases[i]); const annotations = eventsToAnnotations(trends.events || [], days); const windowDays = days.length; return (
{[['full', 'Full history'], ['4w', 'Last 4 weeks']].map(([k, label]) => ( ))}
fmtBedtime(v)} phases={phases} annotations={annotations} range={range} windowDays={windowDays} />
— raw · ewma · 14d ma · vol band on bedtime —
); } window.TrendsTab = TrendsTab;