{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "forgot-password-reset",
  "type": "registry:block",
  "title": "Reset Password",
  "description": "Choose a new password with live requirements and a security panel.",
  "files": [
    {
      "path": "src/registry/blocks/auth/forgot-password-reset.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  type Ref,\n} from \"react\";\nimport { Check, Eye, EyeOff, 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 ResetPasswordValues = { password: string };\n\nexport type PasswordRequirement = {\n  id: string;\n  label: string;\n  test: (password: string) => boolean;\n};\n\nexport type ForgotPasswordResetProps = {\n  /** Product name shown in the wordmark. */\n  brand?: string;\n  title?: string;\n  description?: string;\n  /** The account being reset, shown in mono under the heading. */\n  account?: string;\n  requirements?: PasswordRequirement[];\n  /** Short security note in the side panel. */\n  securityNote?: string;\n  continueHref?: string;\n  signInHref?: string;\n  /** Called with the new password. Throw to show an error. */\n  onSubmit?: (values: ResetPasswordValues) => void | Promise<void>;\n  /** Side panel and primary button ink. Defaults to Devsloka blue. */\n  accent?: string;\n  /** Text colour on `accent`. Defaults to white. */\n  accentForeground?: string;\n} & Omit<ComponentProps<\"section\">, \"onSubmit\">;\n\nconst DEFAULT_REQUIREMENTS: PasswordRequirement[] = [\n  { id: \"length\", label: \"12 characters or more\", test: (p) => p.length >= 12 },\n  { id: \"case\", label: \"Upper and lower case letters\", test: (p) => /[a-z]/.test(p) && /[A-Z]/.test(p) },\n  { id: \"number\", label: \"At least one number\", test: (p) => /\\d/.test(p) },\n  { id: \"spaces\", label: \"No spaces at the start or end\", test: (p) => p.length > 0 && p.trim() === p },\n];\n\nconst DEFAULTS = {\n  brand: \"Larch\",\n  title: \"Choose a new password\",\n  description:\n    \"You’ll use it to sign in on every device. Sessions on other devices end once it’s saved.\",\n  account: \"priya@fieldwork.org\",\n  securityNote:\n    \"Reset links expire after 30 minutes · requested from Lisbon, Chrome on macOS\",\n  accent: \"#0A6EFF\",\n  accentForeground: \"#FFFFFF\",\n};\n\nconst defaultSubmit = () => new Promise<void>((resolve) => setTimeout(resolve, 900));\n\ntype Field = \"password\" | \"confirm\";\ntype Errors = Partial<Record<Field, string>>;\n\nfunction validate(password: string, confirm: string, requirements: PasswordRequirement[]): Errors {\n  const errors: Errors = {};\n  if (!password) errors.password = \"Enter a new password.\";\n  else if (requirements.some((r) => !r.test(password)))\n    errors.password = \"This password doesn’t meet every requirement yet.\";\n  if (!confirm) errors.confirm = \"Type the password again to confirm it.\";\n  else if (password && confirm !== password) errors.confirm = \"The passwords don’t match.\";\n  return errors;\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-current\" />\n      {name}\n    </span>\n  );\n}\n\nfunction KeyholeMark() {\n  return (\n    <svg viewBox=\"0 0 120 160\" aria-hidden=\"true\" className=\"h-32 w-auto\">\n      <rect x=\"0\" y=\"0\" width=\"120\" height=\"160\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" />\n      <circle cx=\"60\" cy=\"62\" r=\"22\" fill=\"currentColor\" />\n      <rect x=\"51\" y=\"70\" width=\"18\" height=\"52\" fill=\"currentColor\" />\n      <rect x=\"0\" y=\"140\" width=\"120\" height=\"2\" fill=\"currentColor\" opacity=\"0.4\" />\n    </svg>\n  );\n}\n\ntype PasswordFieldProps = {\n  id: string;\n  label: string;\n  value: string;\n  onValueChange: (value: string) => void;\n  onBlur: () => void;\n  error?: string;\n  describedBy?: string;\n  inputRef?: Ref<HTMLInputElement>;\n};\n\nfunction PasswordField({\n  id,\n  label,\n  value,\n  onValueChange,\n  onBlur,\n  error,\n  describedBy,\n  inputRef,\n}: PasswordFieldProps) {\n  const [visible, setVisible] = useState(false);\n  const errorId = `${id}-error`;\n  const describedByIds = [describedBy, error ? errorId : undefined].filter(Boolean).join(\" \");\n\n  return (\n    <div className=\"grid gap-2\">\n      <Label htmlFor={id}>{label}</Label>\n      <div className=\"relative\">\n        <Input\n          ref={inputRef}\n          id={id}\n          type={visible ? \"text\" : \"password\"}\n          autoComplete=\"new-password\"\n          required\n          value={value}\n          onChange={(event) => onValueChange(event.target.value)}\n          onBlur={onBlur}\n          aria-invalid={error ? true : undefined}\n          aria-describedby={describedByIds || undefined}\n          className=\"pr-11\"\n        />\n        <button\n          type=\"button\"\n          onClick={() => setVisible((v) => !v)}\n          aria-label={visible ? \"Hide password\" : \"Show password\"}\n          aria-controls={id}\n          className=\"text-muted-foreground hover:text-foreground absolute inset-y-0 right-0 flex w-10 items-center justify-center rounded-sm outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n        >\n          {visible ? <EyeOff aria-hidden=\"true\" className=\"size-4\" /> : <Eye aria-hidden=\"true\" className=\"size-4\" />}\n        </button>\n      </div>\n      {error ? (\n        <p id={errorId} className=\"text-destructive text-xs\">\n          {error}\n        </p>\n      ) : null}\n    </div>\n  );\n}\n\nexport function ForgotPasswordReset({\n  brand = DEFAULTS.brand,\n  title = DEFAULTS.title,\n  description = DEFAULTS.description,\n  account = DEFAULTS.account,\n  requirements = DEFAULT_REQUIREMENTS,\n  securityNote = DEFAULTS.securityNote,\n  continueHref = \"#\",\n  signInHref = \"#\",\n  onSubmit = defaultSubmit,\n  accent = DEFAULTS.accent,\n  accentForeground = DEFAULTS.accentForeground,\n  className,\n  style,\n  ...props\n}: ForgotPasswordResetProps) {\n  const id = useId();\n  const titleId = `${id}-title`;\n  const passwordId = `${id}-password`;\n  const confirmId = `${id}-confirm`;\n  const requirementsId = `${id}-requirements`;\n  const formErrorId = `${id}-form-error`;\n\n  const passwordRef = useRef<HTMLInputElement>(null);\n  const confirmRef = useRef<HTMLInputElement>(null);\n  const successHeadingRef = useRef<HTMLHeadingElement>(null);\n\n  const [password, setPassword] = useState(\"\");\n  const [confirm, setConfirm] = useState(\"\");\n  const [errors, setErrors] = useState<Errors>({});\n  const [formError, setFormError] = useState<string>();\n  const [submitted, setSubmitted] = useState(false);\n  const [status, setStatus] = useState<\"idle\" | \"submitting\" | \"success\">(\"idle\");\n\n  useEffect(() => {\n    if (status === \"success\") successHeadingRef.current?.focus();\n  }, [status]);\n\n  const metCount = requirements.filter((r) => r.test(password)).length;\n\n  const revalidate = () => {\n    if (submitted) setErrors(validate(password, confirm, requirements));\n  };\n\n  const handleSubmit = async (event: FormEvent<HTMLFormElement>) => {\n    event.preventDefault();\n    setSubmitted(true);\n    setFormError(undefined);\n    const nextErrors = validate(password, confirm, requirements);\n    setErrors(nextErrors);\n    if (nextErrors.password) return passwordRef.current?.focus();\n    if (nextErrors.confirm) return confirmRef.current?.focus();\n\n    setStatus(\"submitting\");\n    try {\n      await onSubmit({ password });\n      setStatus(\"success\");\n    } catch {\n      setStatus(\"idle\");\n      setFormError(\n        \"We couldn’t save the new password. Your old one still works. Try again, or request a fresh link if this one has expired.\"\n      );\n    }\n  };\n\n  return (\n    <section\n      data-slot=\"forgot-password-reset\"\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 border md:grid-cols-12\">\n          <aside className=\"flex flex-col justify-between gap-12 bg-[var(--block-accent)] px-6 py-8 text-[var(--block-accent-fg)] md:col-span-4 md:px-8 md:py-10 lg:col-span-3\">\n            <Wordmark name={brand} />\n            <KeyholeMark />\n            <div>\n              <p className=\"font-mono text-[11px] tracking-wider uppercase\">Security note</p>\n              <p className=\"mt-3 font-mono text-xs leading-relaxed\">{securityNote}</p>\n              <p className=\"mt-6 text-xs leading-relaxed\">\n                Didn’t ask for this?{\" \"}\n                <a\n                  href={signInHref}\n                  className=\"rounded-sm underline underline-offset-4 outline-none focus-visible:ring-2 focus-visible:ring-[var(--block-accent-fg)]\"\n                >\n                  Sign in\n                </a>{\" \"}\n                as usual and the link stops working.\n              </p>\n            </div>\n          </aside>\n\n          <div className=\"px-6 py-10 md:col-span-8 md:px-12 md:py-14 lg:col-span-9 lg:px-16\">\n            {status === \"success\" ? (\n              <div className=\"max-w-md\">\n                <p className=\"text-muted-foreground font-mono text-xs tracking-wider uppercase\">\n                  Step 2 of 2 · Done\n                </p>\n                <h2\n                  id={titleId}\n                  ref={successHeadingRef}\n                  tabIndex={-1}\n                  className=\"mt-4 text-4xl font-semibold tracking-[-0.03em] outline-none md:text-5xl\"\n                >\n                  Password updated\n                </h2>\n                <p className=\"text-muted-foreground mt-5 text-base leading-relaxed\">\n                  <span className=\"text-foreground font-mono text-sm\">{account}</span> now signs in\n                  with the new password. We signed you out everywhere else and sent a confirmation\n                  email.\n                </p>\n                <Button\n                  asChild\n                  size=\"lg\"\n                  className=\"mt-10 rounded-none bg-[var(--block-accent)] text-[var(--block-accent-fg)] shadow-none hover:bg-[var(--block-accent)] hover:underline hover:underline-offset-4\"\n                >\n                  <a href={continueHref}>Continue to {brand}</a>\n                </Button>\n              </div>\n            ) : (\n              <div className=\"max-w-md\">\n                <p className=\"text-muted-foreground font-mono text-xs tracking-wider uppercase\">\n                  Step 2 of 2\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 text-base leading-relaxed\">{description}</p>\n                <p className=\"mt-3 font-mono text-sm\">{account}</p>\n\n                <form\n                  noValidate\n                  onSubmit={handleSubmit}\n                  aria-busy={status === \"submitting\"}\n                  aria-describedby={formError ? formErrorId : undefined}\n                  className=\"mt-10 grid gap-6\"\n                >\n                  {/* Hidden username helps password managers save the new password to the right account. */}\n                  <input type=\"hidden\" name=\"username\" autoComplete=\"username\" value={account} />\n\n                  <PasswordField\n                    id={passwordId}\n                    label=\"New password\"\n                    value={password}\n                    onValueChange={setPassword}\n                    onBlur={revalidate}\n                    error={errors.password}\n                    describedBy={requirementsId}\n                    inputRef={passwordRef}\n                  />\n\n                  <div id={requirementsId}>\n                    <p className=\"text-muted-foreground font-mono text-[11px] tracking-wider uppercase\">\n                      Requirements <span className=\"tabular-nums\">{metCount}/{requirements.length}</span>\n                    </p>\n                    <ul className=\"mt-3 grid gap-2 sm:grid-cols-2\">\n                      {requirements.map((requirement) => {\n                        const met = requirement.test(password);\n                        return (\n                          <li\n                            key={requirement.id}\n                            className={cn(\n                              \"flex items-start gap-2 text-sm transition-colors motion-reduce:transition-none\",\n                              met ? \"text-foreground\" : \"text-muted-foreground\"\n                            )}\n                          >\n                            <span\n                              aria-hidden=\"true\"\n                              className={cn(\n                                \"mt-0.5 flex size-4 shrink-0 items-center justify-center border\",\n                                met\n                                  ? \"border-[var(--block-accent)] bg-[var(--block-accent)] text-[var(--block-accent-fg)]\"\n                                  : \"border-border\"\n                              )}\n                            >\n                              {met ? <Check className=\"size-3\" strokeWidth={3} /> : null}\n                            </span>\n                            {requirement.label}\n                            <span className=\"sr-only\">{met ? \"(met)\" : \"(not met yet)\"}</span>\n                          </li>\n                        );\n                      })}\n                    </ul>\n                  </div>\n\n                  <PasswordField\n                    id={confirmId}\n                    label=\"Confirm new password\"\n                    value={confirm}\n                    onValueChange={setConfirm}\n                    onBlur={revalidate}\n                    error={errors.confirm}\n                    inputRef={confirmRef}\n                  />\n\n                  {formError ? (\n                    <p id={formErrorId} className=\"text-destructive border-destructive border-l-2 pl-3 text-sm\">\n                      {formError}\n                    </p>\n                  ) : null}\n\n                  <div className=\"flex flex-wrap items-center justify-between gap-4 border-t pt-6\">\n                    <a\n                      href={signInHref}\n                      className=\"text-muted-foreground hover:text-foreground rounded-sm text-sm underline-offset-4 outline-none hover:underline focus-visible:ring-2 focus-visible:ring-ring\"\n                    >\n                      Back to sign in\n                    </a>\n                    <Button\n                      type=\"submit\"\n                      size=\"lg\"\n                      disabled={status === \"submitting\"}\n                      className=\"rounded-none bg-[var(--block-accent)] text-[var(--block-accent-fg)] shadow-none hover:bg-[var(--block-accent)] hover:underline hover:underline-offset-4\"\n                    >\n                      {status === \"submitting\" ? (\n                        <>\n                          <Loader2 aria-hidden=\"true\" className=\"animate-spin motion-reduce:animate-none\" />\n                          Saving password…\n                        </>\n                      ) : (\n                        \"Save new password\"\n                      )}\n                    </Button>\n                  </div>\n                </form>\n              </div>\n            )}\n\n            <p role=\"status\" aria-live=\"polite\" className=\"sr-only\">\n              {status === \"success\"\n                ? \"Password updated.\"\n                : formError\n                  ? \"The new password was not saved.\"\n                  : \"\"}\n            </p>\n          </div>\n        </div>\n      </div>\n    </section>\n  );\n}\n"
    }
  ],
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "button",
    "input",
    "label"
  ]
}
