{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "countdown-timer",
  "type": "registry:ui",
  "title": "Countdown Timer",
  "description": "A full-screen countdown with fluid rolling digits, play/pause and reset controls, and auto-loop, built with NumberFlow and Motion.",
  "dependencies": [
    "@number-flow/react",
    "motion",
    "lucide-react"
  ],
  "files": [
    {
      "path": "registry/crafterui/ui/countdown-timer.tsx",
      "type": "registry:ui",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport NumberFlow, { NumberFlowGroup } from \"@number-flow/react\"\nimport { Pause, Play, RotateCcw } from \"lucide-react\"\nimport { AnimatePresence, MotionConfig, motion } from \"motion/react\"\n\nimport { cn } from \"@/lib/utils\"\n\nexport interface CountdownTimerProps {\n  /** Starting time in seconds. @default 33 */\n  duration?: number\n  /** Begin counting down immediately on mount. @default true */\n  autoStart?: boolean\n  /** Restart automatically when the timer reaches zero. @default false */\n  loop?: boolean\n  /** Render the play/pause and reset controls. @default true */\n  showControls?: boolean\n  /** Small uppercase caption shown above the numerals with a connector line. @default undefined */\n  label?: string\n  /** Accent color used for the primary play/pause control. @default \"#ff3828\" */\n  accentColor?: string\n  /** Called once the timer reaches zero (not fired while looping). @default undefined */\n  onComplete?: () => void\n  /** Classes for the root element. @default undefined */\n  className?: string\n  /** Classes applied to the numerals — set the display font here. @default undefined */\n  digitClassName?: string\n}\n\nexport function CountdownTimer({\n  duration = 33,\n  autoStart = true,\n  loop = false,\n  showControls = true,\n  label,\n  accentColor = \"#ff3828\",\n  onComplete,\n  className,\n  digitClassName,\n}: CountdownTimerProps) {\n  const [timeLeft, setTimeLeft] = React.useState(duration)\n  const [running, setRunning] = React.useState(autoStart)\n\n  // Reset when the configured duration changes.\n  React.useEffect(() => {\n    setTimeLeft(duration)\n  }, [duration])\n\n  React.useEffect(() => {\n    if (!running) return\n\n    const id = setInterval(() => {\n      setTimeLeft((t) => {\n        if (t <= 1) {\n          if (loop) return duration\n          setRunning(false)\n          return 0\n        }\n        return t - 1\n      })\n    }, 1000)\n\n    return () => clearInterval(id)\n  }, [running, loop, duration])\n\n  React.useEffect(() => {\n    if (timeLeft === 0 && !loop) onComplete?.()\n  }, [timeLeft, loop, onComplete])\n\n  const toggle = () => {\n    // Restart from the top if toggled after completion.\n    if (timeLeft === 0) setTimeLeft(duration)\n    setRunning((r) => !r)\n  }\n\n  const reset = () => {\n    setRunning(false)\n    setTimeLeft(duration)\n  }\n\n  const minutes = Math.floor(timeLeft / 60)\n  const seconds = timeLeft % 60\n\n  return (\n    // NumberFlow already honours the preference on the numerals; this covers the\n    // one thing it does not own - the play/pause glyph swap, which scales.\n    <MotionConfig reducedMotion=\"user\">\n    <div\n      className={cn(\n        \"[container-type:size] relative flex h-full w-full flex-col items-center justify-center gap-8\",\n        className\n      )}\n    >\n      {label ? (\n        <div className=\"absolute top-[11%] left-1/2 grid -translate-x-1/2 justify-items-center text-center\">\n          <span className=\"relative max-w-[12ch] text-[0.7rem] leading-tight tracking-wide uppercase opacity-40 after:absolute after:top-full after:left-1/2 after:h-16 after:w-px after:bg-gradient-to-b after:from-transparent after:to-current after:content-['']\">\n            {label}\n          </span>\n        </div>\n      ) : null}\n\n      <NumberFlowGroup>\n        <div\n          className={cn(\n            \"flex items-baseline leading-none font-bold tracking-tight tabular-nums\",\n            \"text-[clamp(2rem,min(26cqw,40cqh),16rem)]\",\n            digitClassName\n          )}\n        >\n          <NumberFlow value={minutes} trend={-1} />\n          <span className=\"px-[0.04em]\">:</span>\n          <NumberFlow\n            value={seconds}\n            trend={-1}\n            format={{ minimumIntegerDigits: 2 }}\n          />\n        </div>\n      </NumberFlowGroup>\n\n      {showControls ? (\n        <div className=\"flex w-fit items-center gap-2\">\n          <button\n            type=\"button\"\n            onClick={toggle}\n            aria-label={running ? \"Pause timer\" : \"Start timer\"}\n            className=\"focus-visible:outline-foreground flex h-10 w-10 items-center justify-center rounded-full text-white transition-transform outline-none focus-visible:outline-2 focus-visible:outline-offset-2 active:scale-90\"\n            style={{ backgroundColor: accentColor }}\n          >\n            <AnimatePresence mode=\"wait\" initial={false}>\n              <motion.span\n                key={running ? \"pause\" : \"play\"}\n                initial={{ opacity: 0, scale: 0.5 }}\n                animate={{ opacity: 1, scale: 1 }}\n                exit={{ opacity: 0, scale: 0.5 }}\n                transition={{ duration: 0.15 }}\n              >\n                {running ? (\n                  <Pause className=\"h-4 w-4 fill-current\" />\n                ) : (\n                  <Play className=\"h-4 w-4 fill-current\" />\n                )}\n              </motion.span>\n            </AnimatePresence>\n          </button>\n\n          <button\n            type=\"button\"\n            onClick={reset}\n            aria-label=\"Reset timer\"\n            className=\"focus-visible:outline-foreground flex h-10 w-10 items-center justify-center rounded-full bg-black/[0.06] shadow-sm transition-transform outline-none focus-visible:outline-2 focus-visible:outline-offset-2 active:scale-90 dark:bg-white/10\"\n            style={{ color: accentColor }}\n          >\n            <RotateCcw className=\"h-4 w-4\" />\n          </button>\n        </div>\n      ) : null}\n    </div>\n    </MotionConfig>\n  )\n}\n"
    }
  ]
}
