{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "otp-verify",
  "title": "OTP verification",
  "description": "6-digit email code screen that submits by itself, shakes on a wrong code, counts down to resend and lets users change their email.",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "button",
    "input",
    "input-otp",
    "label"
  ],
  "files": [
    {
      "path": "registry/blocks/auth/otp-verify.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { ArrowLeft, CheckCircle2, Loader2, MailCheck, RotateCw, ShieldCheck } from \"lucide-react\"\nimport { Button } from \"@/components/ui/button\"\nimport { Input } from \"@/components/ui/input\"\nimport { InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot } from \"@/components/ui/input-otp\"\nimport { Label } from \"@/components/ui/label\"\nimport { cn } from \"@/lib/utils\"\n\nconst CORRECT = \"424242\"\nconst COOLDOWN = 30\nconst MAX_ATTEMPTS = 5\n\nfunction mask(email: string) {\n  const [user = \"\", domain] = email.split(\"@\")\n  if (!domain) return email\n  return `${user[0]}${\"•\".repeat(Math.max(2, Math.min(user.length - 1, 6)))}@${domain}`\n}\n\nexport default function OtpVerify() {\n  const [email, setEmail] = React.useState(\"emma.clarke@northside.studio\")\n  const [view, setView] = React.useState<\"code\" | \"email\" | \"done\">(\"code\")\n  const [code, setCode] = React.useState(\"\")\n  const [status, setStatus] = React.useState<\"idle\" | \"checking\" | \"error\">(\"idle\")\n  const [attempts, setAttempts] = React.useState(0)\n  const [shake, setShake] = React.useState(0)\n  const [seconds, setSeconds] = React.useState(COOLDOWN)\n  const [sent, setSent] = React.useState<string | null>(null)\n  const [draft, setDraft] = React.useState(\"\")\n  const [draftError, setDraftError] = React.useState<string | null>(null)\n\n  // Resend countdown\n  React.useEffect(() => {\n    if (view !== \"code\" || seconds <= 0) return\n    const id = setTimeout(() => setSeconds((s) => s - 1), 1000)\n    return () => clearTimeout(id)\n  }, [seconds, view])\n\n  const locked = attempts >= MAX_ATTEMPTS\n\n  const verify = (value: string) => {\n    if (locked) return\n    setStatus(\"checking\")\n    setSent(null)\n    setTimeout(() => {\n      if (value === CORRECT) {\n        setView(\"done\")\n        setStatus(\"idle\")\n        return\n      }\n      setAttempts((a) => a + 1)\n      setStatus(\"error\")\n      setShake((n) => n + 1)\n      setCode(\"\")\n    }, 800)\n  }\n\n  const resend = () => {\n    setSeconds(COOLDOWN)\n    setAttempts(0)\n    setCode(\"\")\n    setStatus(\"idle\")\n    setSent(`New code sent to ${mask(email)}`)\n  }\n\n  const changeEmail = (e: React.FormEvent) => {\n    e.preventDefault()\n    if (!/^\\S+@\\S+\\.\\S+$/.test(draft)) {\n      setDraftError(\"Enter a valid email address\")\n      return\n    }\n    if (draft.toLowerCase() === email.toLowerCase()) {\n      setDraftError(\"That's the email we already sent the code to\")\n      return\n    }\n    setEmail(draft)\n    setView(\"code\")\n    setCode(\"\")\n    setAttempts(0)\n    setStatus(\"idle\")\n    setSeconds(COOLDOWN)\n    setSent(`Code sent to ${mask(draft)}`)\n  }\n\n  const left = MAX_ATTEMPTS - attempts\n  const mm = String(Math.floor(seconds / 60)).padStart(1, \"0\")\n  const ss = String(seconds % 60).padStart(2, \"0\")\n\n  return (\n    <div className=\"flex min-h-svh items-center justify-center bg-background px-4 py-10\">\n      <style>{`@keyframes otp-shake{0%,100%{transform:translateX(0)}20%{transform:translateX(-10px)}40%{transform:translateX(9px)}60%{transform:translateX(-6px)}80%{transform:translateX(4px)}}`}</style>\n      <div className=\"w-full max-w-md text-center\">\n        {/* Illustration */}\n        <div className=\"relative mx-auto mb-8 flex size-36 items-center justify-center\">\n          <span className=\"absolute inset-0 rounded-full border border-dashed border-border\" />\n          <span className=\"absolute inset-4 rounded-full border border-border bg-muted/40\" />\n          <span className=\"absolute inset-9 rounded-full bg-gradient-to-b from-primary/20 to-primary/5\" />\n          <span className={cn(\"relative flex size-14 items-center justify-center rounded-2xl shadow-lg transition-colors\", view === \"done\" ? \"bg-emerald-500 text-white\" : status === \"error\" ? \"bg-destructive text-white\" : \"bg-primary text-primary-foreground\")}>\n            {view === \"done\" ? <ShieldCheck className=\"size-7\" /> : <MailCheck className=\"size-7\" />}\n          </span>\n          <span className=\"absolute top-3 right-4 size-2.5 rounded-full bg-[var(--chart-2)]\" />\n          <span className=\"absolute bottom-6 left-2 size-2 rounded-full bg-[var(--chart-4)]\" />\n          <span className=\"absolute top-10 left-1 size-1.5 rounded-full bg-[var(--chart-1)]\" />\n        </div>\n\n        {view === \"code\" && (\n          <div className=\"animate-in duration-300 fade-in\">\n            <h1 className=\"text-2xl font-semibold tracking-tight\">Check your email</h1>\n            <p className=\"mt-2 text-sm text-muted-foreground\">\n              We sent a 6-digit code to <span className=\"font-medium text-foreground\">{mask(email)}</span>.<br />Enter it below to confirm it's you.\n            </p>\n\n            <div key={shake} className=\"mt-8 flex justify-center\" style={shake ? { animation: \"otp-shake 0.45s ease-in-out\" } : undefined}>\n              <InputOTP\n                maxLength={6}\n                value={code}\n                pattern=\"^[0-9]+$\"\n                inputMode=\"numeric\"\n                autoFocus\n                disabled={status === \"checking\" || locked}\n                aria-label=\"Verification code\"\n                onChange={(v) => {\n                  setCode(v)\n                  if (status === \"error\") setStatus(\"idle\")\n                }}\n                onComplete={verify}\n              >\n                <InputOTPGroup>\n                  {[0, 1, 2].map((i) => <InputOTPSlot key={i} index={i} aria-invalid={status === \"error\"} className=\"size-12 text-xl font-semibold sm:size-14\" />)}\n                </InputOTPGroup>\n                <InputOTPSeparator />\n                <InputOTPGroup>\n                  {[3, 4, 5].map((i) => <InputOTPSlot key={i} index={i} aria-invalid={status === \"error\"} className=\"size-12 text-xl font-semibold sm:size-14\" />)}\n                </InputOTPGroup>\n              </InputOTP>\n            </div>\n\n            <div className=\"mt-4 min-h-10 text-sm\" aria-live=\"polite\">\n              {status === \"checking\" && <span className=\"inline-flex items-center gap-2 text-muted-foreground\"><Loader2 className=\"size-4 animate-spin\" /> Verifying…</span>}\n              {status === \"error\" && !locked && <span className=\"text-destructive\">That code isn't right. {left} attempt{left === 1 ? \"\" : \"s\"} left.</span>}\n              {locked && <span className=\"text-destructive\">Too many incorrect codes. Request a new one to continue.</span>}\n              {status === \"idle\" && !locked && sent && <span className=\"text-emerald-600 dark:text-emerald-400\">{sent}</span>}\n              {status === \"idle\" && !locked && !sent && <span className=\"text-muted-foreground\">Demo code: <code className=\"font-mono font-semibold text-foreground\">424242</code></span>}\n            </div>\n\n            <div className=\"mt-4 flex flex-col items-center gap-3 border-t pt-6 text-sm\">\n              <div className=\"text-muted-foreground\">\n                Didn't get it?{\" \"}\n                {seconds > 0 && !locked ? (\n                  <span>Resend in <span className=\"font-mono font-medium text-foreground tabular-nums\">{mm}:{ss}</span></span>\n                ) : (\n                  <button type=\"button\" onClick={resend} className=\"inline-flex items-center gap-1 font-medium text-primary hover:underline\"><RotateCw className=\"size-3.5\" /> Resend code</button>\n                )}\n              </div>\n              <button type=\"button\" onClick={() => { setDraft(\"\"); setDraftError(null); setView(\"email\") }} className=\"text-muted-foreground underline-offset-4 hover:text-foreground hover:underline\">\n                Wrong address? Change email\n              </button>\n            </div>\n          </div>\n        )}\n\n        {view === \"email\" && (\n          <form noValidate onSubmit={changeEmail} className=\"animate-in text-left duration-300 fade-in slide-in-from-bottom-2\">\n            <h1 className=\"text-center text-2xl font-semibold tracking-tight\">Use a different email</h1>\n            <p className=\"mt-2 text-center text-sm text-muted-foreground\">We'll send a fresh code and forget the old one.</p>\n            <div className=\"mt-6 flex flex-col gap-1.5\">\n              <Label htmlFor=\"otp-email\">Email address</Label>\n              <Input id=\"otp-email\" type=\"email\" autoFocus className=\"h-10\" placeholder=\"you@yourstudio.com\" value={draft} aria-invalid={!!draftError} onChange={(e) => { setDraft(e.target.value); setDraftError(null) }} />\n              {draftError && <p className=\"text-xs text-destructive\">{draftError}</p>}\n            </div>\n            <div className=\"mt-4 flex gap-2\">\n              <Button type=\"button\" variant=\"outline\" size=\"lg\" onClick={() => setView(\"code\")}><ArrowLeft /> Back</Button>\n              <Button type=\"submit\" size=\"lg\" className=\"flex-1\">Send new code</Button>\n            </div>\n          </form>\n        )}\n\n        {view === \"done\" && (\n          <div className=\"animate-in duration-300 fade-in zoom-in-95\">\n            <h1 className=\"inline-flex items-center gap-2 text-2xl font-semibold tracking-tight\"><CheckCircle2 className=\"size-6 text-emerald-600 dark:text-emerald-400\" /> Email verified</h1>\n            <p className=\"mt-2 text-sm text-muted-foreground\"><span className=\"font-medium text-foreground\">{email}</span> is confirmed. Booking confirmations and receipts will go here.</p>\n            <Button size=\"lg\" variant=\"outline\" className=\"mt-6\" onClick={() => { setView(\"code\"); setCode(\"\"); setAttempts(0); setSent(null); setSeconds(COOLDOWN) }}>\n              Run the demo again\n            </Button>\n          </div>\n        )}\n      </div>\n    </div>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/otp-verify.tsx"
    }
  ],
  "categories": [
    "auth"
  ],
  "type": "registry:block"
}