{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "app-auth-reset",
  "type": "registry:block",
  "title": "App, reset password",
  "description": "Ask for a password reset link: one email field, a send button, a confirmation that does not reveal whether the address has an account, a resend button, and idle, sending, sent and error states.",
  "categories": [
    "app"
  ],
  "dependencies": [
    "zod@^4.6.5"
  ],
  "registryDependencies": [
    "https://ui.klarhimmel.com/r/banner.json",
    "https://ui.klarhimmel.com/r/block-kit.json",
    "https://ui.klarhimmel.com/r/button.json",
    "https://ui.klarhimmel.com/r/editing.json",
    "https://ui.klarhimmel.com/r/input.json",
    "https://ui.klarhimmel.com/r/kit-app.json",
    "https://ui.klarhimmel.com/r/kit-auth.json",
    "https://ui.klarhimmel.com/r/kit-form.json"
  ],
  "files": [
    {
      "path": "src/blocks/app-auth-reset/spec.ts",
      "type": "registry:file",
      "target": "components/klarhimmel/blocks/app-auth-reset/spec.ts",
      "content": "import { z } from 'zod';\nimport { defineSpec, formFields, link, req, t } from '../_shared/schema';\n\nconst schema = z.object({\n  eyebrow: t(60).optional(),\n  title: t(120),\n  description: t(300).optional(),\n  emailLabel: req(40),\n  emailHint: t(120).optional(),\n  submit: t(30),\n  sending: t(30),\n  /** Offered once the link has been sent. */\n  resend: req(30),\n  back: link,\n  /** idle, sending, sent (the confirmation shows and the button offers to send again), error (the email field is marked and described). */\n  state: z.enum(['idle', 'sending', 'sent', 'error']),\n  messages: z.object({ sent: t(160), error: t(160), emailError: t(120) }),\n  ...formFields,\n});\n\nexport const spec = defineSpec({\n  type: 'app-auth-reset',\n  aliases: ['app/auth-reset'],\n  name: 'App, reset password',\n  category: 'app',\n  role: 'body',\n  description: 'Ask for a password reset link: one email field, a send button, a confirmation that does not reveal whether the address has an account, a resend button, and idle, sending, sent and error states.',\n  schema,\n  defaults: {\n    \"eyebrow\": \"Name the section\",\n    \"title\": \"Say what this page is for\",\n    \"description\": \"Say which address to enter and what will be sent to it.\",\n    \"emailLabel\": \"Email address\",\n    \"emailHint\": \"Say where the link goes.\",\n    \"submit\": \"Send reset link\",\n    \"sending\": \"Sending…\",\n    \"resend\": \"Send it again\",\n    \"back\": {\n      \"label\": \"Back to sign in\",\n      \"href\": \"#sign-in\"\n    },\n    \"state\": \"idle\",\n    \"messages\": {\n      \"sent\": \"Say that a link is on its way if the address has an account, and where to look.\",\n      \"error\": \"Say that the email was not sent and to try again.\",\n      \"emailError\": \"Say what a valid address looks like.\"\n    }\n  },\n});\n"
    },
    {
      "path": "src/blocks/app-auth-reset/index.tsx",
      "type": "registry:file",
      "target": "components/klarhimmel/blocks/app-auth-reset/index.tsx",
      "content": "import { useId, useRef } from 'react';\nimport { Text, withHeadingLevel } from '../../editing';\nimport { Banner } from '../../ui/banner';\nimport { Button } from '../../ui/button';\nimport { Input } from '../../ui/input';\nimport { Container, Opt, Section, SectionHeader } from '../_shared/kit';\nimport { AppPanel, StateSlot, Swap, useSynced } from '../_shared/app-kit';\nimport { FieldRow, LabelLink, describedBy } from '../_shared/auth-kit';\nimport { FormExtras, useFormProps } from '../_shared/form-kit';\nimport { spec } from './spec';\nimport type { BlockProps } from '../types';\nimport type { z } from 'zod';\n\nexport { spec };\ntype Props = z.infer<typeof spec.schema>;\n\nfunction AppAuthReset({ props }: BlockProps<Props>) {\n  const id = useId();\n  const form = useFormProps(props);\n  const field = useRef<HTMLInputElement>(null);\n  const [again, setAgain] = useSynced(0, props.state); // times \"send it again\" was pressed while the link was sent\n  const banner = useRef<HTMLDivElement>(null);\n  const { state } = props;\n  const invalid = state === 'error';\n  return (\n    <Section labelledBy={id}>\n      <Container width=\"narrow\" className=\"max-w-md\">\n        <SectionHeader id={id} eyebrow={props.eyebrow} title={props.title} description={props.description} />\n        <AppPanel className=\"mt-8\">\n          <form\n            {...form}\n            onSubmit={(e) => {\n              if (state === 'sent') {\n                e.preventDefault();\n                setAgain(again + 1); // the confirmation is said again, so the press is answered\n                banner.current?.focus();\n                return;\n              }\n              form.onSubmit?.(e);\n            }}\n            aria-busy={state === 'sending' || undefined} className=\"p-6 @xl:p-8\">\n            <fieldset disabled={state === 'sending'} className=\"m-0 flex min-w-0 flex-col gap-5 border-0 p-0\">\n            <StateSlot show={state === 'sent'}>\n              <div ref={banner} tabIndex={-1} className=\"outline-none\">\n                <Banner key={again} tone=\"info\">\n                  <Text path={['messages', 'sent']} value={props.messages.sent} as=\"span\" />\n                </Banner>\n              </div>\n            </StateSlot>\n            <FieldRow\n              id={`${id}-m`}\n              label={<Text path={['emailLabel']} value={props.emailLabel} as=\"span\" />}\n              hint={<Opt path={['emailHint']} value={props.emailHint} as=\"span\" placeholder=\"Hint\" />}\n              error={<Text path={['messages', 'emailError']} value={props.messages.emailError} as=\"span\" />}\n              showError={invalid}\n            >\n              <Input ref={field} id={`${id}-m`} name=\"email\" type=\"email\" autoComplete=\"email\" autoCapitalize=\"none\" spellCheck={false} required aria-invalid={invalid || undefined} aria-describedby={describedBy(`${id}-m`, !!props.emailHint, invalid)} />\n            </FieldRow>\n            <StateSlot show={state === 'error'}>\n              <Banner tone=\"error\">\n                <Text path={['messages', 'error']} value={props.messages.error} as=\"span\" />\n              </Banner>\n            </StateSlot>\n            <FormExtras {...props} />\n            <Button type=\"submit\" full disabled={state === 'sending'} formNoValidate={state === 'sent'}>\n              <Swap show={state !== 'sending' && state !== 'sent'}>\n                <Text path={['submit']} value={props.submit} as=\"span\" />\n              </Swap>\n              <Swap show={state === 'sending'}>\n                <Text path={['sending']} value={props.sending} as=\"span\" />\n              </Swap>\n              <Swap show={state === 'sent'}>\n                <Text path={['resend']} value={props.resend} as=\"span\" />\n              </Swap>\n            </Button>\n            </fieldset>\n          </form>\n        </AppPanel>\n        <p className=\"mt-6 text-center text-kh-small\">\n          <LabelLink path={['back']} link={props.back} />\n        </p>\n      </Container>\n    </Section>\n  );\n}\n\nexport default withHeadingLevel(AppAuthReset);\n"
    }
  ]
}
