{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "flag-new-version-reload",
  "title": "Flag New Version Reload",
  "description": "A flag that announces a new app version with Reload now and Later, where Later snoozes it for a set time and a second release overrides the snooze.",
  "registryDependencies": [
    "@tealmac/flag"
  ],
  "files": [
    {
      "path": "registry/patterns/flag-new-version-reload/flag-new-version-reload.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { Flag } from \"@/components/ui/flag\"\n\nexport interface FlagNewVersionReloadProps {\n  /** The version the server now serves, or null when nothing new. */\n  availableVersion: string | null\n  /** Called when the person chooses Reload now. */\n  onReload: () => void\n  /** Snooze time after Later, in ms. Default 3600000 (one hour). */\n  snoozeMs?: number\n  /** Clock override for tests. */\n  now?: () => number\n}\n\n/**\n * Updates should not interrupt unsaved work, so the flag gives two honest\n * options. Reload now calls onReload; Later hides the flag for `snoozeMs`. If a\n * newer version appears while snoozed, the snooze is ignored for it (the person\n * said later about the old one), so nobody ends up running an old build for\n * days. Nothing is shown when no version is available.\n */\nexport function FlagNewVersionReload({\n  availableVersion,\n  onReload,\n  snoozeMs = 3600000,\n  now = Date.now,\n}: FlagNewVersionReloadProps) {\n  const [snooze, setSnooze] = React.useState<{\n    version: string\n    until: number\n  } | null>(null)\n  const [, tick] = React.useReducer((n: number) => n + 1, 0)\n\n  React.useEffect(() => {\n    if (!snooze) return\n    const wait = Math.max(0, snooze.until - now())\n    const id = setTimeout(tick, wait + 5)\n    return () => clearTimeout(id)\n  }, [snooze, now])\n\n  if (!availableVersion) return null\n  if (snooze && snooze.version === availableVersion && now() < snooze.until)\n    return null\n\n  return (\n    <Flag\n      appearance=\"info\"\n      title=\"A new version is available\"\n      description={`Version ${availableVersion} has fixes and improvements. Save your work before reloading.`}\n      actions={[\n        { content: \"Reload now\", onClick: onReload },\n        {\n          content: \"Later\",\n          onClick: () =>\n            setSnooze({ version: availableVersion, until: now() + snoozeMs }),\n        },\n      ]}\n    />\n  )\n}\n",
      "type": "registry:block"
    }
  ],
  "type": "registry:block"
}