{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "button-countdown-confirm",
  "type": "registry:component",
  "title": "Button Countdown Confirm",
  "description": "A destructive button that arms on the first press, drains a countdown ring next to a Cancel button and confirms on its own at zero.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "buttons",
    "button",
    "confirm",
    "countdown",
    "destructive",
    "undo",
    "delete"
  ],
  "docs": "https://hyperblur.dev/effects/button-countdown-confirm",
  "files": [
    {
      "path": "registry/hyperblur/button-countdown-confirm.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/button-countdown-confirm.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface ButtonCountdownConfirmProps\n  extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, \"color\" | \"onClick\" | \"children\"> {\n  children?: React.ReactNode;\n  onConfirm?: () => void;\n  onCancel?: () => void;\n  seconds?: number;\n  pendingLabel?: string;\n  cancelLabel?: string;\n  doneLabel?: string;\n  variant?: \"solid\" | \"outline\";\n  accent?: string;\n  size?: \"sm\" | \"md\" | \"lg\";\n  defaultArmed?: boolean;\n  loading?: boolean;\n}\n\ntype Phase = \"idle\" | \"armed\" | \"done\";\n\nconst trash = (\n  <svg viewBox=\"0 0 24 24\" width=\"1.1em\" height=\"1.1em\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n    <path d=\"M4 7h16\" />\n    <path d=\"M9 7V4h6v3\" />\n    <path d=\"M6 7l1 13h10l1-13\" />\n    <path d=\"M10 11v5M14 11v5\" />\n  </svg>\n);\n\nconst check = (\n  <svg viewBox=\"0 0 24 24\" width=\"1.1em\" height=\"1.1em\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.4\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n    <path d=\"M5 12.5l4.5 4.5L19 7.5\" />\n  </svg>\n);\n\nconst css = `\n.hb-ya5 {\n  --hb-ya5-h: 2.75rem;\n  --hb-ya5-fs: 0.9375rem;\n  display: inline-flex;\n  align-items: center;\n  box-sizing: border-box;\n  font: inherit;\n  font-size: var(--hb-ya5-fs);\n}\n.hb-ya5 *, .hb-ya5 *::before, .hb-ya5 *::after { box-sizing: border-box; }\n.hb-ya5[data-size=\"sm\"] { --hb-ya5-h: 2.25rem; --hb-ya5-fs: 0.8125rem; }\n.hb-ya5[data-size=\"lg\"] { --hb-ya5-h: 3.25rem; --hb-ya5-fs: 1.0625rem; }\n.hb-ya5-main {\n  position: relative;\n  display: inline-grid;\n  place-items: center;\n  height: var(--hb-ya5-h);\n  margin: 0;\n  padding: 0 1.3em;\n  overflow: hidden;\n  font: inherit;\n  font-weight: 600;\n  line-height: 1;\n  white-space: nowrap;\n  border: 1px solid transparent;\n  border-radius: 12px;\n  cursor: pointer;\n  user-select: none;\n  -webkit-user-select: none;\n  -webkit-tap-highlight-color: transparent;\n  transition: background-color 0.25s ease, border-color 0.25s ease, color 0.25s ease, transform 0.18s cubic-bezier(0.3, 1.4, 0.5, 1);\n}\n.hb-ya5[data-variant=\"solid\"] .hb-ya5-main { color: #fff; background: var(--hb-ya5-c); }\n.hb-ya5[data-variant=\"solid\"] .hb-ya5-main:not(:disabled):hover { background: color-mix(in srgb, var(--hb-ya5-c) 88%, #fff); }\n.hb-ya5[data-variant=\"solid\"][data-phase=\"armed\"] .hb-ya5-main { background: color-mix(in srgb, var(--hb-ya5-c) 70%, #000); }\n.hb-ya5[data-variant=\"outline\"] .hb-ya5-main {\n  color: color-mix(in srgb, var(--hb-ya5-c) 70%, #fff);\n  background: transparent;\n  border-color: color-mix(in srgb, var(--hb-ya5-c) 55%, #262626);\n}\n.hb-ya5[data-variant=\"outline\"] .hb-ya5-main:not(:disabled):hover { background: color-mix(in srgb, var(--hb-ya5-c) 10%, transparent); }\n.hb-ya5[data-variant=\"outline\"][data-phase=\"armed\"] .hb-ya5-main { background: color-mix(in srgb, var(--hb-ya5-c) 16%, transparent); border-color: var(--hb-ya5-c); }\n.hb-ya5-main:not(:disabled):active { transform: scale(0.97); }\n.hb-ya5-main:focus-visible { outline: 2px solid var(--hb-ya5-c); outline-offset: 3px; }\n.hb-ya5-cancel:focus-visible { outline: 2px solid var(--hb-ya5-c); outline-offset: -2px; }\n.hb-ya5-main:disabled { opacity: 0.45; cursor: not-allowed; }\n.hb-ya5-main[aria-busy=\"true\"] { cursor: progress; }\n.hb-ya5-state {\n  grid-area: 1 / 1;\n  display: inline-flex;\n  align-items: center;\n  gap: 0.6em;\n  visibility: hidden;\n  opacity: 0;\n  transform: translateY(6px);\n  transition: opacity 0.2s ease, transform 0.3s cubic-bezier(0.3, 0.9, 0.3, 1), visibility 0s linear 0.3s;\n}\n.hb-ya5[data-phase=\"idle\"] .hb-ya5-idle,\n.hb-ya5[data-phase=\"armed\"] .hb-ya5-armed,\n.hb-ya5[data-phase=\"done\"] .hb-ya5-done {\n  visibility: visible;\n  opacity: 1;\n  transform: none;\n  transition-delay: 0s;\n}\n.hb-ya5-ring {\n  position: relative;\n  display: grid;\n  flex: none;\n  place-items: center;\n  width: 1.6em;\n  height: 1.6em;\n}\n.hb-ya5-ring > svg {\n  position: absolute;\n  inset: 0;\n  width: 100%;\n  height: 100%;\n  transform: rotate(-90deg);\n}\n.hb-ya5-track { fill: none; stroke: currentColor; stroke-width: 2.4; opacity: 0.25; }\n.hb-ya5-prog {\n  fill: none;\n  stroke: currentColor;\n  stroke-width: 2.4;\n  stroke-linecap: round;\n  stroke-dasharray: 62.83;\n  stroke-dashoffset: 0;\n  animation: hb-ya5-drain var(--hb-ya5-t, 3s) linear forwards;\n}\n.hb-ya5-num {\n  position: relative;\n  font-size: 0.72em;\n  font-variant-numeric: tabular-nums;\n}\n.hb-ya5-time { font-variant-numeric: tabular-nums; }\n.hb-ya5-cancelwrap {\n  display: grid;\n  grid-template-columns: 0fr;\n  transition: grid-template-columns 0.4s cubic-bezier(0.3, 0.9, 0.3, 1);\n}\n.hb-ya5[data-phase=\"armed\"] .hb-ya5-cancelwrap { grid-template-columns: 1fr; }\n.hb-ya5-cliprow { min-width: 0; overflow: hidden; }\n.hb-ya5-cancel {\n  display: block;\n  height: var(--hb-ya5-h);\n  margin: 0 0 0 0.5rem;\n  padding: 0 1.1em;\n  font: inherit;\n  font-weight: 500;\n  line-height: 1;\n  color: #d4d4d4;\n  background: transparent;\n  border: 1px solid #2a2a2a;\n  border-radius: 12px;\n  cursor: pointer;\n  white-space: nowrap;\n  opacity: 0;\n  transition: opacity 0.25s ease, background-color 0.2s ease, border-color 0.2s ease;\n}\n.hb-ya5[data-phase=\"armed\"] .hb-ya5-cancel { opacity: 1; transition-delay: 0.1s; }\n.hb-ya5-cancel:hover { background: #171717; border-color: #3a3a3a; }\n.hb-ya5-spin {\n  width: 1.1em;\n  height: 1.1em;\n  border: 2px solid currentColor;\n  border-right-color: transparent;\n  border-radius: 50%;\n  animation: hb-ya5-turn 0.7s linear infinite;\n}\n.hb-ya5-sr {\n  position: absolute;\n  width: 1px;\n  height: 1px;\n  margin: -1px;\n  padding: 0;\n  overflow: hidden;\n  clip-path: inset(50%);\n  white-space: nowrap;\n  border: 0;\n}\n@keyframes hb-ya5-drain {\n  to { stroke-dashoffset: 62.83; }\n}\n@keyframes hb-ya5-turn {\n  to { transform: rotate(360deg); }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-ya5-main, .hb-ya5-state, .hb-ya5-cancelwrap, .hb-ya5-cancel { transition: none; }\n  .hb-ya5-main:not(:disabled):active { transform: none; }\n  .hb-ya5-prog { animation: none; }\n  .hb-ya5-spin { animation-duration: 2s; }\n}\n`;\n\nexport function ButtonCountdownConfirm({\n  children = \"Delete project\",\n  onConfirm,\n  onCancel,\n  seconds = 3,\n  pendingLabel = \"Deleting in {s}s\",\n  cancelLabel = \"Cancel\",\n  doneLabel = \"Deleted\",\n  variant = \"solid\",\n  accent = \"#ff4d5e\",\n  size = \"md\",\n  defaultArmed = false,\n  loading = false,\n  disabled = false,\n  type = \"button\",\n  className = \"\",\n  style,\n  ...rest\n}: ButtonCountdownConfirmProps) {\n  const total = Math.max(1, Math.round(seconds));\n  const mainRef = React.useRef<HTMLButtonElement>(null);\n  const latest = React.useRef({ onConfirm, onCancel });\n  const [phase, setPhase] = React.useState<Phase>(defaultArmed ? \"armed\" : \"idle\");\n  const [left, setLeft] = React.useState(total);\n\n  React.useEffect(() => {\n    latest.current = { onConfirm, onCancel };\n  }, [onConfirm, onCancel]);\n\n  const finish = React.useCallback(() => {\n    latest.current.onConfirm?.();\n    setPhase(\"done\");\n  }, []);\n\n  React.useEffect(() => {\n    if (phase !== \"armed\") return;\n    const tick = window.setInterval(() => setLeft((value) => Math.max(0, value - 1)), 1000);\n    const end = window.setTimeout(finish, total * 1000);\n    return () => {\n      window.clearInterval(tick);\n      window.clearTimeout(end);\n    };\n  }, [phase, total, finish]);\n\n  React.useEffect(() => {\n    if (phase !== \"done\") return;\n    const timer = window.setTimeout(() => setPhase(\"idle\"), 1700);\n    return () => window.clearTimeout(timer);\n  }, [phase]);\n\n  function cancel() {\n    setPhase(\"idle\");\n    latest.current.onCancel?.();\n    mainRef.current?.focus();\n  }\n\n  function press() {\n    if (disabled || loading) return;\n    if (phase === \"idle\") {\n      setLeft(total);\n      setPhase(\"armed\");\n    } else if (phase === \"armed\") {\n      finish();\n    }\n  }\n\n  const armed = phase === \"armed\";\n  const vars = {\n    \"--hb-ya5-c\": accent,\n    \"--hb-ya5-t\": `${total}s`,\n    ...style,\n  } as React.CSSProperties;\n  const pending = pendingLabel.replace(\"{s}\", String(left));\n\n  return (\n    <>\n      <style href=\"hb-button-countdown-confirm\" precedence=\"default\">{css}</style>\n      <span\n        className={`hb-ya5 ${className}`}\n        style={vars}\n        data-variant={variant}\n        data-size={size}\n        data-phase={phase}\n        onKeyDown={(e) => {\n          if (e.key === \"Escape\" && armed) {\n            e.preventDefault();\n            cancel();\n          }\n        }}\n      >\n        <button\n          ref={mainRef}\n          type={type}\n          className=\"hb-ya5-main\"\n          disabled={disabled}\n          aria-busy={loading || undefined}\n          onClick={press}\n          {...rest}\n        >\n          <span className=\"hb-ya5-state hb-ya5-idle\" aria-hidden={phase !== \"idle\"}>\n            {loading ? <span className=\"hb-ya5-spin\" aria-hidden=\"true\" /> : trash}\n            {children}\n          </span>\n          <span className=\"hb-ya5-state hb-ya5-armed\" aria-hidden={!armed}>\n            {armed ? (\n              <span className=\"hb-ya5-ring\" aria-hidden=\"true\">\n                <svg viewBox=\"0 0 24 24\">\n                  <circle className=\"hb-ya5-track\" cx=\"12\" cy=\"12\" r=\"10\" />\n                  <circle className=\"hb-ya5-prog\" cx=\"12\" cy=\"12\" r=\"10\" />\n                </svg>\n                <span className=\"hb-ya5-num\">{left}</span>\n              </span>\n            ) : null}\n            <span className=\"hb-ya5-time\">{pending}</span>\n          </span>\n          <span className=\"hb-ya5-state hb-ya5-done\" aria-hidden={phase !== \"done\"}>\n            {check}\n            {doneLabel}\n          </span>\n        </button>\n        <span className=\"hb-ya5-cancelwrap\">\n          <span className=\"hb-ya5-cliprow\">\n            <button\n              type=\"button\"\n              className=\"hb-ya5-cancel\"\n              tabIndex={armed ? 0 : -1}\n              aria-hidden={!armed}\n              disabled={!armed}\n              onClick={cancel}\n            >\n              {cancelLabel}\n            </button>\n          </span>\n        </span>\n        <span className=\"hb-ya5-sr\" role=\"status\" aria-live=\"polite\">\n          {armed\n            ? `Confirming in ${total} seconds. Press Escape or ${cancelLabel} to stop.`\n            : phase === \"done\"\n              ? doneLabel\n              : \"\"}\n        </span>\n      </span>\n    </>\n  );\n}\n"
    }
  ]
}