{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "otp-input",
  "type": "registry:ui",
  "title": "OTP Input",
  "dependencies": [
    "motion",
    "lucide-react"
  ],
  "files": [
    {
      "path": "components/ui/otp-input.tsx",
      "content": "\"use client\";\n\nimport React, { useRef, useState } from \"react\";\nimport { motion } from \"motion/react\";\nimport { CheckCircle2, RotateCcw, ShieldCheck } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface OtpInputProps {\n  length?: number;\n  onComplete?: (code: string) => void;\n  className?: string;\n}\n\nexport function OtpInput({\n  length = 6,\n  onComplete,\n  className,\n}: OtpInputProps) {\n  const [digits, setDigits] = useState<string[]>(Array(length).fill(\"\"));\n  const [focusedIdx, setFocusedIdx] = useState<number | null>(null);\n  const inputsRef = useRef<Array<HTMLInputElement | null>>([]);\n\n  const code = digits.join(\"\");\n  const isComplete = code.length === length && !digits.includes(\"\");\n\n  const updateDigit = (index: number, val: string) => {\n    const clean = val.replace(/\\D/g, \"\");\n    if (!clean) {\n      const next = [...digits];\n      next[index] = \"\";\n      setDigits(next);\n      return;\n    }\n\n    // Handle multi-char paste or rapid typing\n    const chars = clean.slice(0, length - index).split(\"\");\n    const next = [...digits];\n    chars.forEach((ch, offset) => {\n      next[index + offset] = ch;\n    });\n    setDigits(next);\n\n    const nextFocus = Math.min(length - 1, index + chars.length);\n    inputsRef.current[nextFocus]?.focus();\n\n    const joined = next.join(\"\");\n    if (joined.length === length && !next.includes(\"\")) {\n      onComplete?.(joined);\n    }\n  };\n\n  const handleKeyDown = (index: number, e: React.KeyboardEvent<HTMLInputElement>) => {\n    if (e.key === \"Backspace\") {\n      if (digits[index]) {\n        const next = [...digits];\n        next[index] = \"\";\n        setDigits(next);\n      } else if (index > 0) {\n        const next = [...digits];\n        next[index - 1] = \"\";\n        setDigits(next);\n        inputsRef.current[index - 1]?.focus();\n      }\n      e.preventDefault();\n    } else if (e.key === \"ArrowLeft\" && index > 0) {\n      inputsRef.current[index - 1]?.focus();\n    } else if (e.key === \"ArrowRight\" && index < length - 1) {\n      inputsRef.current[index + 1]?.focus();\n    }\n  };\n\n  const fillDemo = () => {\n    const sample = \"482910\".slice(0, length).split(\"\");\n    setDigits(sample);\n    onComplete?.(sample.join(\"\"));\n  };\n\n  const reset = () => {\n    setDigits(Array(length).fill(\"\"));\n    inputsRef.current[0]?.focus();\n  };\n\n  return (\n    <div\n      className={cn(\n        \"w-full max-w-sm rounded-2xl border border-white/10 bg-[#101013] p-5 shadow-[inset_0_1px_0_rgba(255,255,255,0.06)]\",\n        className\n      )}\n    >\n      <div className=\"flex items-center justify-between\">\n        <div className=\"flex items-center gap-2\">\n          <div className=\"flex h-7 w-7 items-center justify-center rounded-lg border border-white/10 bg-zinc-900 text-blue-400\">\n            <ShieldCheck className=\"h-4 w-4\" />\n          </div>\n          <div>\n            <h3 className=\"text-xs font-semibold text-zinc-100\">\n              Two-Factor Verification\n            </h3>\n            <p className=\"text-[11px] text-zinc-500\">\n              Enter the {length}-digit code\n            </p>\n          </div>\n        </div>\n\n        <button\n          type=\"button\"\n          onClick={isComplete ? reset : fillDemo}\n          className=\"inline-flex items-center gap-1 rounded-md border border-white/10 bg-zinc-900 px-2 py-1 text-[10px] text-zinc-400 hover:text-zinc-100 cursor-pointer transition-colors\"\n        >\n          {isComplete ? (\n            <>\n              <RotateCcw className=\"h-3 w-3\" />\n              Clear\n            </>\n          ) : (\n            \"Auto-fill\"\n          )}\n        </button>\n      </div>\n\n      <div className=\"mt-4 flex items-center justify-between gap-2\">\n        {digits.map((digit, idx) => {\n          const isFocused = focusedIdx === idx;\n          return (\n            <motion.div\n              key={idx}\n              animate={{\n                scale: digit ? [1, 1.08, 1] : 1,\n                borderColor: isComplete\n                  ? \"rgba(52,211,153,0.6)\"\n                  : isFocused\n                    ? \"rgba(96,165,250,0.8)\"\n                    : \"rgba(255,255,255,0.1)\",\n              }}\n              transition={{ duration: 0.18 }}\n              className=\"relative flex h-12 flex-1 items-center justify-center rounded-xl border bg-zinc-950\"\n            >\n              <input\n                ref={(el) => {\n                  inputsRef.current[idx] = el;\n                }}\n                type=\"text\"\n                inputMode=\"numeric\"\n                maxLength={length}\n                value={digit}\n                aria-label={`Digit ${idx + 1}`}\n                onFocus={() => setFocusedIdx(idx)}\n                onBlur={() => setFocusedIdx(null)}\n                onChange={(e) => updateDigit(idx, e.target.value)}\n                onKeyDown={(e) => handleKeyDown(idx, e)}\n                className=\"h-full w-full bg-transparent text-center font-mono text-lg font-semibold text-zinc-100 focus:outline-none\"\n              />\n            </motion.div>\n          );\n        })}\n      </div>\n\n      <div className=\"mt-3 flex min-h-[18px] items-center justify-between text-[11px]\">\n        {isComplete ? (\n          <motion.span\n            initial={{ opacity: 0, y: 3 }}\n            animate={{ opacity: 1, y: 0 }}\n            className=\"inline-flex items-center gap-1.5 font-medium text-emerald-400\"\n          >\n            <CheckCircle2 className=\"h-3.5 w-3.5\" />\n            Code {code} verified\n          </motion.span>\n        ) : (\n          <span className=\"text-zinc-500\">Supports paste &amp; arrow keys</span>\n        )}\n      </div>\n    </div>\n  );\n}\n\n",
      "type": "registry:ui"
    }
  ]
}