{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "confirm-with-countdown",
  "title": "Confirm With Countdown",
  "description": "An alert dialog whose destructive button unlocks after a countdown that restarts each time it opens; use this when a rushed click is the main risk.",
  "registryDependencies": [
    "alert-dialog",
    "button"
  ],
  "files": [
    {
      "path": "registry/patterns/confirm-with-countdown/confirm-with-countdown.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport {\n  AlertDialog,\n  AlertDialogCancel,\n  AlertDialogContent,\n  AlertDialogDescription,\n  AlertDialogFooter,\n  AlertDialogHeader,\n  AlertDialogTitle,\n  AlertDialogTrigger,\n} from \"@/components/ui/alert-dialog\"\nimport { Button } from \"@/components/ui/button\"\n\nexport interface ConfirmWithCountdownProps {\n  /** The element that opens the dialog. */\n  children: React.ReactNode\n  onConfirm: () => void\n  /** Seconds the confirm button stays locked. Default 5. */\n  seconds?: number\n  title?: React.ReactNode\n  description?: React.ReactNode\n  actionLabel?: string\n}\n\n/**\n * An alert dialog whose destructive button unlocks after a countdown. The wait\n * restarts every time the dialog opens, and the remaining seconds are in the\n * button label, so a rushed click cannot confirm by accident.\n */\nexport function ConfirmWithCountdown({\n  children,\n  onConfirm,\n  seconds = 5,\n  title = \"Are you sure?\",\n  description = \"This action cannot be undone.\",\n  actionLabel = \"Delete\",\n}: ConfirmWithCountdownProps) {\n  const [open, setOpen] = React.useState(false)\n  const [left, setLeft] = React.useState(seconds)\n\n  React.useEffect(() => {\n    if (!open) return\n    setLeft(seconds)\n    const timer = window.setInterval(() => {\n      setLeft((value) => {\n        if (value <= 1) window.clearInterval(timer)\n        return Math.max(0, value - 1)\n      })\n    }, 1000)\n    return () => window.clearInterval(timer)\n  }, [open, seconds])\n\n  return (\n    <AlertDialog open={open} onOpenChange={setOpen}>\n      <AlertDialogTrigger asChild>{children}</AlertDialogTrigger>\n      <AlertDialogContent>\n        <AlertDialogHeader>\n          <AlertDialogTitle>{title}</AlertDialogTitle>\n          <AlertDialogDescription>{description}</AlertDialogDescription>\n        </AlertDialogHeader>\n        <AlertDialogFooter>\n          <AlertDialogCancel>Cancel</AlertDialogCancel>\n          <Button\n            variant=\"destructive\"\n            disabled={left > 0}\n            onClick={() => {\n              onConfirm()\n              setOpen(false)\n            }}\n          >\n            {left > 0 ? `${actionLabel} (${left})` : actionLabel}\n          </Button>\n        </AlertDialogFooter>\n      </AlertDialogContent>\n    </AlertDialog>\n  )\n}\n",
      "type": "registry:block"
    }
  ],
  "type": "registry:block"
}