{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "verify-email",
  "type": "registry:block",
  "title": "Verify Email",
  "description": "The 6-digit code step: a centred code field split 3 + 3, a shake when the code is wrong, a resend timer that counts down and a mail icon that turns into a check.",
  "categories": [
    "screen",
    "Auth"
  ],
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "utils",
    "https://coss.com/ui/r/button.json",
    "https://coss.com/ui/r/otp-field.json"
  ],
  "files": [
    {
      "path": "registry/devl/verify-email.tsx",
      "type": "registry:component",
      "content": "\"use client\";\n\nimport { CheckIcon, MailIcon } from \"lucide-react\";\nimport { AnimatePresence, motion, useAnimationControls, useReducedMotion } from \"motion/react\";\nimport { useEffect, useId, useState } from \"react\";\nimport { Button } from \"@/components/ui/button\";\nimport { OTPField, OTPFieldInput, OTPFieldSeparator } from \"@/components/ui/otp-field\";\nimport { cn } from \"@/lib/utils\";\n\nexport type VerifyResult = { ok: true } | { ok: false; error: string };\n\nexport interface VerifyEmailProps {\n  email?: string;\n  length?: number;\n  resendAfter?: number;\n  onVerify?: (code: string) => Promise<VerifyResult>;\n  onResend?: () => void;\n  onChangeEmail?: () => void;\n  onContinue?: () => void;\n  className?: string;\n}\n\nasync function demoVerify(code: string): Promise<VerifyResult> {\n  await new Promise((resolve) => setTimeout(resolve, 800));\n  if (/^(\\d)\\1+$/.test(code)) return { ok: false, error: \"That code didn’t work. Check the email and try again.\" };\n  return { ok: true };\n}\n\nfunction Tile({ done }: { done: boolean }) {\n  return (\n    <span\n      className={cn(\n        \"relative flex size-10 items-center justify-center overflow-hidden rounded-xl border shadow-xs/5 transition-colors duration-300\",\n        done ? \"border-success/30 bg-success/10 text-success-foreground\" : \"bg-card text-foreground\",\n      )}\n    >\n      <AnimatePresence initial={false} mode=\"popLayout\">\n        <motion.span\n          animate={{ opacity: 1, y: 0 }}\n          className=\"flex\"\n          exit={{ opacity: 0, y: -10 }}\n          initial={{ opacity: 0, y: 10 }}\n          key={done ? \"done\" : \"mail\"}\n          transition={{ type: \"spring\", stiffness: 420, damping: 30 }}\n        >\n          {done ? <CheckIcon className=\"size-5\" /> : <MailIcon className=\"size-5\" />}\n        </motion.span>\n      </AnimatePresence>\n    </span>\n  );\n}\n\nexport function VerifyEmail({\n  email = \"ada@ridgeline.app\",\n  length = 6,\n  resendAfter = 30,\n  onVerify = demoVerify,\n  onResend,\n  onChangeEmail,\n  onContinue,\n  className,\n}: VerifyEmailProps) {\n  const id = useId();\n  const reduce = useReducedMotion();\n  const shake = useAnimationControls();\n  const [code, setCode] = useState(\"\");\n  const [busy, setBusy] = useState(false);\n  const [error, setError] = useState<string | null>(null);\n  const [done, setDone] = useState(false);\n  const [left, setLeft] = useState(resendAfter);\n\n  useEffect(() => {\n    if (left <= 0 || done) return;\n    const timer = setTimeout(() => setLeft((value) => value - 1), 1000);\n    return () => clearTimeout(timer);\n  }, [left, done]);\n\n  const verify = async (value: string) => {\n    if (busy || done || value.length < length) return;\n    setBusy(true);\n    setError(null);\n    const result = await onVerify(value);\n    setBusy(false);\n    if (result.ok) {\n      setDone(true);\n      return;\n    }\n    setError(result.error);\n    if (!reduce) await shake.start({ x: [0, -6, 6, -4, 4, 0], transition: { duration: 0.36 } });\n  };\n\n  const half = Math.ceil(length / 2);\n\n  return (\n    <div className={cn(\"flex h-[760px] w-full flex-col overflow-y-auto bg-background px-6 py-10 text-foreground\", className)}>\n      <div className=\"m-auto flex w-full max-w-[340px] flex-col items-center\">\n        <Tile done={done} />\n        <h1 className=\"mt-6 text-balance text-center font-semibold text-xl tracking-tight\">{done ? \"Email verified\" : \"Check your email\"}</h1>\n        <p className=\"mt-1.5 text-balance text-center text-muted-foreground text-sm\">\n          {done ? (\n            <>\n              <span className=\"font-medium text-foreground\">{email}</span> is confirmed. You’re all set.\n            </>\n          ) : (\n            <>\n              Enter the {length}-digit code we sent to <span className=\"font-medium text-foreground\">{email}</span>\n            </>\n          )}\n        </p>\n\n        <form\n          className=\"mt-8 flex w-full flex-col items-center gap-4\"\n          onSubmit={(event) => {\n            event.preventDefault();\n            if (done) onContinue?.();\n            else verify(code);\n          }}\n        >\n          <motion.div animate={shake}>\n            <label className=\"sr-only\" htmlFor={`${id}-code`}>\n              Verification code\n            </label>\n            <OTPField\n              aria-describedby={error ? `${id}-error` : undefined}\n              aria-label=\"Verification code\"\n              id={`${id}-code`}\n              disabled={busy || done}\n              length={length}\n              onValueChange={(value) => {\n                setCode(value);\n                setError(null);\n              }}\n              onValueComplete={verify}\n              size=\"lg\"\n              value={code}\n            >\n              {Array.from({ length }, (_, i) => (\n                <span className=\"contents\" key={i}>\n                  {i === half && <OTPFieldSeparator />}\n                  <OTPFieldInput\n                    aria-invalid={error ? true : undefined}\n                    aria-label={`Digit ${i + 1} of ${length}`}\n                    className={cn(\"transition-colors duration-300\", done && \"border-success/40 bg-success/6\")}\n                  />\n                </span>\n              ))}\n            </OTPField>\n          </motion.div>\n          {error && (\n            <p className=\"-mt-1 text-center text-destructive-foreground text-xs\" id={`${id}-error`} role=\"alert\">\n              {error}\n            </p>\n          )}\n          <Button className=\"mt-2 w-full\" disabled={!done && code.length < length} loading={busy} type=\"submit\">\n            {done ? \"Continue\" : \"Verify email\"}\n          </Button>\n        </form>\n\n        <p className=\"mt-6 text-center text-muted-foreground text-sm\">\n          {done ? null : left > 0 ? (\n            <>\n              Didn’t get a code? Resend in <span className=\"font-medium text-foreground tabular-nums\">0:{String(left).padStart(2, \"0\")}</span>\n            </>\n          ) : (\n            <>\n              Didn’t get a code?{\" \"}\n              <button\n                className=\"cursor-pointer rounded-sm font-medium text-foreground underline-offset-4 outline-none hover:underline focus-visible:ring-2 focus-visible:ring-ring\"\n                onClick={() => {\n                  onResend?.();\n                  setLeft(resendAfter);\n                }}\n                type=\"button\"\n              >\n                Resend\n              </button>\n            </>\n          )}\n        </p>\n\n        <p className={cn(\"mt-8 text-center text-muted-foreground text-sm\", done && \"invisible\")}>\n          Wrong email?{\" \"}\n          <button\n            className=\"cursor-pointer rounded-sm font-medium text-foreground underline-offset-4 outline-none hover:underline focus-visible:ring-2 focus-visible:ring-ring\"\n            onClick={onChangeEmail}\n            type=\"button\"\n          >\n            Change it\n          </button>\n        </p>\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}