{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "incident-banner-maintenance-window",
  "title": "Incident Banner Maintenance Window",
  "description": "A scheduled maintenance banner that changes by the clock from upcoming, with a start countdown, to in progress and to completed, without any manual update.",
  "registryDependencies": [
    "@tealmac/incident-banner"
  ],
  "files": [
    {
      "path": "registry/patterns/incident-banner-maintenance-window/incident-banner-maintenance-window.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { IncidentBanner } from \"@/components/ui/incident-banner\"\n\nexport interface IncidentBannerMaintenanceWindowProps {\n  title: string\n  /** ISO start and end. */\n  start: string\n  end: string\n  /** Clock override for tests: returns ms since the epoch. */\n  now?: () => number\n}\n\nfunction relative(ms: number) {\n  const m = Math.round(ms / 60000)\n  if (m < 60) return `${m} minute${m === 1 ? \"\" : \"s\"}`\n  const h = Math.round(m / 60)\n  if (h < 48) return `${h} hour${h === 1 ? \"\" : \"s\"}`\n  const d = Math.round(h / 24)\n  return `${d} days`\n}\n\n/**\n * Maintenance is announced ahead of time and should speak for itself on the\n * day. The banner picks its wording from the clock: \"starts in 3 hours\", then\n * \"in progress, ends in 40 minutes\", then \"completed\". The check re-runs each\n * minute, and the last phase switches the severity to resolved.\n */\nexport function IncidentBannerMaintenanceWindow({\n  title,\n  start,\n  end,\n  now = Date.now,\n}: IncidentBannerMaintenanceWindowProps) {\n  const [t, setT] = React.useState(() => now())\n  React.useEffect(() => {\n    const id = setInterval(() => setT(now()), 60000)\n    return () => clearInterval(id)\n  }, [now])\n\n  const s = Date.parse(start)\n  const e = Date.parse(end)\n  const phase = t < s ? \"upcoming\" : t < e ? \"active\" : \"done\"\n  const when = (ms: number) =>\n    new Date(ms).toISOString().slice(0, 16).replace(\"T\", \" \") + \" UTC\"\n\n  return (\n    <IncidentBanner\n      severity={phase === \"done\" ? \"resolved\" : \"maintenance\"}\n      title={title}\n      updates={[\n        {\n          time:\n            phase === \"upcoming\"\n              ? when(s)\n              : phase === \"active\"\n                ? when(s)\n                : when(e),\n          stage:\n            phase === \"upcoming\"\n              ? \"Scheduled\"\n              : phase === \"active\"\n                ? \"In progress\"\n                : \"Completed\",\n          message:\n            phase === \"upcoming\"\n              ? `Starts in ${relative(s - t)}. Expect short interruptions until ${when(e)}.`\n              : phase === \"active\"\n                ? `Ends in about ${relative(e - t)}.`\n                : \"Everything is back to normal.\",\n        },\n      ]}\n    />\n  )\n}\n",
      "type": "registry:block"
    }
  ],
  "type": "registry:block"
}