/** * The Article 14 reporting clock: a horizontal track from the moment you become * aware, with ticks at 24 hours, 72 hours and the final report. The first two * are drawn to scale; the final report hangs off a dashed segment because its * deadline depends on when a fix is available (or, for a severe incident, on * when the notification was sent). */ import { useEffect, useState } from 'react'; export type StageState = 'done' | 'overdue' | 'soon' | 'pending' | 'static'; export interface ClockStage { name: string; /** Shown in mono above the name: an absolute time, or "+24 hours". */ when: string; state: StageState; /** Short status line under the name. */ status?: string; } /** Tick positions (%). 24 h and 72 h are to scale; the final report sits at the end. */ const POSITIONS = [22, 62, 100]; export function ReportingClock({ start, stages, startWhen, startName = 'Aware', label }: { /** ISO time the manufacturer became aware. Omit for the static explainer. */ start?: string | null; stages: [ClockStage, ClockStage, ClockStage]; startWhen: string; startName?: string; /** Accessible name for the group. */ label?: string; }) { const now = useNow(start ? 60_000 : null); const elapsed = start ? elapsedPosition(start, now, stages) : null; return (
  1. {startWhen} {startName} Clock starts
  2. {stages.map((stage) => (
  3. {stage.when} {stage.name} {stage.status && ( {stage.status} )}
  4. ))}
); } function useNow(interval: number | null): number { const [now, setNow] = useState(() => Date.now()); useEffect(() => { if (!interval) return undefined; const id = window.setInterval(() => setNow(Date.now()), interval); return () => window.clearInterval(id); }, [interval]); return now; } const HOUR = 3_600_000; function elapsedPosition(start: string, now: number, stages: ClockStage[]): number | null { const startMs = Date.parse(start); if (Number.isNaN(startMs)) return null; const hours = (now - startMs) / HOUR; if (hours <= 0) return 0; if (hours <= 72) return (hours / 72) * 62; // Past 72 hours: show progress along the dashed segment without implying a date. if (stages[2].state === 'done') return 100; return Math.min(95, 62 + Math.min(33, ((hours - 72) / (14 * 24)) * 33)); }