{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "forgot-password-simple",
  "type": "registry:block",
  "title": "Forgot Password",
  "description": "Request a reset link, then a check-your-email screen with a resend cooldown.",
  "files": [
    {
      "path": "src/registry/blocks/auth/forgot-password-simple.tsx",
      "type": "registry:block",
      "content": "\"use client\";\n\nimport {\n  useEffect,\n  useId,\n  useRef,\n  useState,\n  type ComponentProps,\n  type CSSProperties,\n  type FormEvent,\n} from \"react\";\nimport { Loader2 } from \"lucide-react\";\n\nimport { Button } from \"@/components/ui/button\";\nimport { Input } from \"@/components/ui/input\";\nimport { Label } from \"@/components/ui/label\";\nimport { cn } from \"@/lib/utils\";\n\nexport type ForgotPasswordValues = { email: string };\n\nexport type ForgotPasswordSimpleProps = {\n  /** Product name shown in the wordmark. */\n  brand?: string;\n  eyebrow?: string;\n  title?: string;\n  description?: string;\n  /** Numbered next steps shown after the link is sent. */\n  nextSteps?: string[];\n  /** Seconds before \"Resend\" becomes available again. */\n  resendCooldown?: number;\n  signInHref?: string;\n  supportHref?: string;\n  /** Called with the email when the form is submitted. Throw to show an error. */\n  onSubmit?: (values: ForgotPasswordValues) => void | Promise<void>;\n  /** Called when the person asks for another email. Defaults to `onSubmit`. */\n  onResend?: (values: ForgotPasswordValues) => void | Promise<void>;\n  /** Ink for the wordmark square, rule and primary button. Defaults to Devsloka blue. */\n  accent?: string;\n  /** Text colour on `accent`. */\n  accentForeground?: string;\n} & Omit<ComponentProps<\"section\">, \"onSubmit\">;\n\nconst DEFAULTS = {\n  brand: \"Larch\",\n  eyebrow: \"Account recovery\",\n  title: \"Forgot your password?\",\n  description:\n    \"Enter the email you use for Larch and we will send a link to choose a new password.\",\n  nextSteps: [\n    \"Open the email from Larch. It usually arrives within a minute.\",\n    \"Select “Choose a new password”. The link works once and expires after 30 minutes.\",\n    \"Not there? Check spam or the Promotions tab, then resend below.\",\n  ],\n  accent: \"#0A6EFF\",\n  accentForeground: \"#FFFFFF\",\n};\n\nconst EMAIL_PATTERN = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\n\nfunction validateEmail(email: string) {\n  if (!email.trim()) return \"Enter the email address on your account.\";\n  if (!EMAIL_PATTERN.test(email.trim())) return \"That email looks incomplete. Check for a typo.\";\n  return undefined;\n}\n\nconst defaultSubmit = () => new Promise<void>((resolve) => setTimeout(resolve, 900));\n\nconst pad = (n: number) => String(n).padStart(2, \"0\");\nconst formatSeconds = (s: number) => `${Math.floor(s / 60)}:${pad(s % 60)}`;\n\n/** Counts down once per second while `seconds > 0`. The interval starts when `start()` is called. */\nfunction useCooldown() {\n  const [seconds, setSeconds] = useState(0);\n  const running = seconds > 0;\n\n  useEffect(() => {\n    if (!running) return;\n    const timer = setInterval(() => {\n      setSeconds((current) => Math.max(0, current - 1));\n    }, 1000);\n    return () => clearInterval(timer);\n  }, [running]);\n\n  return [seconds, setSeconds] as const;\n}\n\nfunction Wordmark({ name }: { name: string }) {\n  return (\n    <span className=\"inline-flex items-center gap-2 text-base font-semibold tracking-tight\">\n      <span aria-hidden=\"true\" className=\"size-2.5 bg-[var(--block-accent)]\" />\n      {name}\n    </span>\n  );\n}\n\nexport function ForgotPasswordSimple({\n  brand = DEFAULTS.brand,\n  eyebrow = DEFAULTS.eyebrow,\n  title = DEFAULTS.title,\n  description = DEFAULTS.description,\n  nextSteps = DEFAULTS.nextSteps,\n  resendCooldown = 30,\n  signInHref = \"#\",\n  supportHref = \"#\",\n  onSubmit = defaultSubmit,\n  onResend,\n  accent = DEFAULTS.accent,\n  accentForeground = DEFAULTS.accentForeground,\n  className,\n  style,\n  ...props\n}: ForgotPasswordSimpleProps) {\n  const id = useId();\n  const emailId = `${id}-email`;\n  const errorId = `${id}-email-error`;\n  const titleId = `${id}-title`;\n  const inputRef = useRef<HTMLInputElement>(null);\n  const confirmHeadingRef = useRef<HTMLHeadingElement>(null);\n\n  const [email, setEmail] = useState(\"\");\n  const [sentTo, setSentTo] = useState(\"\");\n  const [error, setError] = useState<string>();\n  const [submitted, setSubmitted] = useState(false);\n  const [status, setStatus] = useState<\"idle\" | \"submitting\" | \"success\">(\"idle\");\n  const [resending, setResending] = useState(false);\n  const [announcement, setAnnouncement] = useState(\"\");\n  const [cooldown, setCooldown] = useCooldown();\n\n  useEffect(() => {\n    if (status === \"success\") confirmHeadingRef.current?.focus();\n  }, [status]);\n\n  const handleSubmit = async (event: FormEvent<HTMLFormElement>) => {\n    event.preventDefault();\n    setSubmitted(true);\n    const nextError = validateEmail(email);\n    setError(nextError);\n    if (nextError) {\n      inputRef.current?.focus();\n      return;\n    }\n\n    const values = { email: email.trim() };\n    setStatus(\"submitting\");\n    setAnnouncement(\"\");\n    try {\n      await onSubmit(values);\n      setSentTo(values.email);\n      setStatus(\"success\");\n      setCooldown(resendCooldown);\n      setAnnouncement(`Reset link sent to ${values.email}.`);\n    } catch {\n      setStatus(\"idle\");\n      setError(\n        \"We couldn’t send the email just now. Your account is fine. Try again in a minute.\"\n      );\n      setAnnouncement(\"The reset email was not sent.\");\n    }\n  };\n\n  const handleResend = async () => {\n    if (cooldown > 0 || resending) return;\n    setResending(true);\n    setAnnouncement(\"\");\n    try {\n      await (onResend ?? onSubmit)({ email: sentTo });\n      setCooldown(resendCooldown);\n      setAnnouncement(`Sent another link to ${sentTo}. Use the newest email.`);\n    } catch {\n      setAnnouncement(\"We couldn’t resend the email. Try again in a minute.\");\n    } finally {\n      setResending(false);\n    }\n  };\n\n  const changeEmail = () => {\n    setStatus(\"idle\");\n    setCooldown(0);\n    setAnnouncement(\"\");\n    requestAnimationFrame(() => inputRef.current?.focus());\n  };\n\n  return (\n    <section\n      data-slot=\"forgot-password-simple\"\n      aria-labelledby={titleId}\n      style={\n        {\n          \"--block-accent\": accent,\n          \"--block-accent-fg\": accentForeground,\n          ...style,\n        } as CSSProperties\n      }\n      className={cn(\"w-full bg-background text-foreground\", className)}\n      {...props}\n    >\n      <div className=\"mx-auto max-w-6xl px-6 py-16 md:py-24\">\n        <div className=\"grid gap-10 md:grid-cols-12 md:gap-8\">\n          <div className=\"flex items-start justify-between md:col-span-3 md:flex-col md:justify-start md:gap-10\">\n            <Wordmark name={brand} />\n            <p className=\"text-muted-foreground font-mono text-xs tracking-wider uppercase\">\n              {status === \"success\" ? \"02 — Check inbox\" : \"01 — Request link\"}\n            </p>\n          </div>\n\n          <div className=\"border-t-2 border-[var(--block-accent)] pt-8 md:col-span-7 md:col-start-5 lg:col-span-6 lg:col-start-5\">\n            {status === \"success\" ? (\n              <div>\n                <p className=\"text-muted-foreground font-mono text-xs tracking-wider uppercase\">\n                  {eyebrow}\n                </p>\n                <h2\n                  id={titleId}\n                  ref={confirmHeadingRef}\n                  tabIndex={-1}\n                  className=\"mt-4 text-4xl font-semibold tracking-[-0.03em] outline-none md:text-5xl\"\n                >\n                  Check your email\n                </h2>\n                <p className=\"text-muted-foreground mt-5 max-w-prose text-base leading-relaxed\">\n                  We sent a reset link to\n                </p>\n                <p className=\"mt-1 font-mono text-sm break-all\">{sentTo}</p>\n\n                <ol className=\"mt-10 divide-y border-y\">\n                  {nextSteps.map((step, index) => (\n                    <li key={step} className=\"grid grid-cols-[2.5rem_1fr] gap-x-2 py-4 text-sm leading-relaxed\">\n                      <span\n                        aria-hidden=\"true\"\n                        className=\"font-mono text-xs leading-6 font-semibold tabular-nums text-[var(--block-accent)] dark:text-foreground\"\n                      >\n                        {pad(index + 1)}\n                      </span>\n                      <span>{step}</span>\n                    </li>\n                  ))}\n                </ol>\n\n                <div className=\"mt-8 flex flex-wrap items-center gap-x-6 gap-y-3 text-sm\">\n                  <button\n                    type=\"button\"\n                    onClick={handleResend}\n                    disabled={cooldown > 0 || resending}\n                    className=\"rounded-sm font-medium underline decoration-1 underline-offset-[6px] outline-none hover:decoration-2 focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:text-muted-foreground disabled:no-underline\"\n                  >\n                    {resending ? (\n                      \"Resending…\"\n                    ) : cooldown > 0 ? (\n                      <>\n                        Resend in <span className=\"font-mono tabular-nums\">{formatSeconds(cooldown)}</span>\n                      </>\n                    ) : (\n                      \"Resend email\"\n                    )}\n                  </button>\n                  <button\n                    type=\"button\"\n                    onClick={changeEmail}\n                    className=\"text-muted-foreground hover:text-foreground rounded-sm underline-offset-[6px] outline-none hover:underline focus-visible:ring-2 focus-visible:ring-ring\"\n                  >\n                    Use a different address\n                  </button>\n                </div>\n\n                <div className=\"mt-12 flex items-center justify-between gap-4 border-t pt-6 text-sm\">\n                  <a\n                    href={signInHref}\n                    className=\"rounded-sm font-medium underline-offset-4 outline-none hover:underline focus-visible:ring-2 focus-visible:ring-ring\"\n                  >\n                    ← Back to sign in\n                  </a>\n                  <a\n                    href={supportHref}\n                    className=\"text-muted-foreground hover:text-foreground rounded-sm text-xs underline-offset-4 outline-none hover:underline focus-visible:ring-2 focus-visible:ring-ring\"\n                  >\n                    Still stuck? Contact support\n                  </a>\n                </div>\n              </div>\n            ) : (\n              <div>\n                <p className=\"text-muted-foreground font-mono text-xs tracking-wider uppercase\">\n                  {eyebrow}\n                </p>\n                <h2\n                  id={titleId}\n                  className=\"mt-4 text-4xl font-semibold tracking-[-0.03em] text-balance md:text-5xl\"\n                >\n                  {title}\n                </h2>\n                <p className=\"text-muted-foreground mt-5 max-w-md text-base leading-relaxed\">\n                  {description}\n                </p>\n\n                <form\n                  noValidate\n                  onSubmit={handleSubmit}\n                  aria-busy={status === \"submitting\"}\n                  className=\"mt-10 grid max-w-md gap-6\"\n                >\n                  <div className=\"grid gap-2\">\n                    <Label htmlFor={emailId}>Email</Label>\n                    <Input\n                      ref={inputRef}\n                      id={emailId}\n                      name=\"email\"\n                      type=\"email\"\n                      autoComplete=\"email\"\n                      inputMode=\"email\"\n                      required\n                      value={email}\n                      onChange={(event) => setEmail(event.target.value)}\n                      onBlur={() => {\n                        if (submitted) setError(validateEmail(email));\n                      }}\n                      aria-invalid={error ? true : undefined}\n                      aria-describedby={error ? errorId : undefined}\n                      placeholder=\"you@fieldwork.org\"\n                    />\n                    {error ? (\n                      <p id={errorId} className=\"text-destructive text-xs\">\n                        {error}\n                      </p>\n                    ) : null}\n                  </div>\n\n                  <Button\n                    type=\"submit\"\n                    size=\"lg\"\n                    disabled={status === \"submitting\"}\n                    className=\"w-full rounded-none bg-[var(--block-accent)] text-[var(--block-accent-fg)] shadow-none hover:bg-[var(--block-accent)] hover:underline hover:underline-offset-4 sm:w-auto sm:justify-self-start\"\n                  >\n                    {status === \"submitting\" ? (\n                      <>\n                        <Loader2 aria-hidden=\"true\" className=\"animate-spin motion-reduce:animate-none\" />\n                        Sending link…\n                      </>\n                    ) : (\n                      \"Send reset link\"\n                    )}\n                  </Button>\n                </form>\n\n                <p className=\"text-muted-foreground mt-12 border-t pt-6 text-sm\">\n                  Remembered it?{\" \"}\n                  <a\n                    href={signInHref}\n                    className=\"text-foreground rounded-sm font-medium underline-offset-4 outline-none hover:underline focus-visible:ring-2 focus-visible:ring-ring\"\n                  >\n                    Back to sign in\n                  </a>\n                </p>\n              </div>\n            )}\n\n            <p role=\"status\" aria-live=\"polite\" className=\"sr-only\">\n              {announcement}\n            </p>\n          </div>\n        </div>\n      </div>\n    </section>\n  );\n}\n"
    }
  ],
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "button",
    "input",
    "label"
  ]
}
