{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "contact-block",
  "type": "registry:block",
  "title": "Contact Block",
  "description": "A Contact Block component for displaying contact information.",
  "files": [
    {
      "path": "src/registry/blocks/contact-block.tsx",
      "type": "registry:block",
      "content": "\"use client\";\n\nimport { useId, useRef, useState, type ComponentProps, type FormEvent } from \"react\";\nimport { ArrowUpRight, Loader2 } from \"lucide-react\";\n\nimport { Button } from \"@/components/ui/button\";\nimport { Input } from \"@/components/ui/input\";\nimport { Label } from \"@/components/ui/label\";\nimport { RadioGroup, RadioGroupItem } from \"@/components/ui/radio-group\";\nimport { Textarea } from \"@/components/ui/textarea\";\nimport { cn } from \"@/lib/utils\";\n\nexport type ContactValues = {\n  name: string;\n  email: string;\n  company: string;\n  topic: string;\n  message: string;\n};\n\nexport type ContactChannel = {\n  label: string;\n  value: string;\n  href?: string;\n  detail?: string;\n};\n\nexport type ContactBlockProps = {\n  eyebrow?: string;\n  title?: string;\n  intro?: string;\n  channels?: ContactChannel[];\n  responseNote?: string;\n  topics?: string[];\n  onSubmit?: (values: ContactValues) => void | Promise<void>;\n} & Omit<ComponentProps<\"section\">, \"onSubmit\">;\n\nconst DEFAULT_CHANNELS: ContactChannel[] = [\n  {\n    label: \"New work\",\n    value: \"projects@halden.studio\",\n    href: \"mailto:projects@halden.studio\",\n    detail: \"Briefs, budgets, timelines. A rough outline is fine.\",\n  },\n  {\n    label: \"Everything else\",\n    value: \"hello@halden.studio\",\n    href: \"mailto:hello@halden.studio\",\n    detail: \"Press, talks, internships, saying hello.\",\n  },\n  {\n    label: \"Studio\",\n    value: \"Torstraße 118, 10119 Berlin\",\n    detail: \"Mon–Thu, 09:30–18:00 CET. Visits by appointment.\",\n  },\n];\n\nconst DEFAULT_TOPICS = [\"New project\", \"Existing project\", \"Press\", \"Something else\"];\n\ntype Errors = Partial<Record<keyof ContactValues, string>>;\n\nconst EMAIL_PATTERN = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\n\nfunction validate(values: ContactValues): Errors {\n  const errors: Errors = {};\n  if (!values.name.trim()) errors.name = \"Tell us who you are.\";\n  if (!values.email.trim()) errors.email = \"We need an email to reply to.\";\n  else if (!EMAIL_PATTERN.test(values.email.trim()))\n    errors.email = \"That email looks incomplete — check for a typo.\";\n  if (!values.topic) errors.topic = \"Pick the closest topic.\";\n  if (values.message.trim().length < 20)\n    errors.message = \"A sentence or two, please (20 characters minimum).\";\n  return errors;\n}\n\nconst defaultSubmit = () =>\n  new Promise<void>((resolve) => setTimeout(resolve, 900));\n\nexport default function ContactBlock({\n  eyebrow = \"Contact\",\n  title = \"Start with an email. We'll take it from there.\",\n  intro = \"Halden is a six-person design studio working on identities, websites and the occasional book. We take on four or five projects a year.\",\n  channels = DEFAULT_CHANNELS,\n  responseNote = \"We reply within one working day.\",\n  topics = DEFAULT_TOPICS,\n  onSubmit = defaultSubmit,\n  className,\n  ...props\n}: ContactBlockProps) {\n  const id = useId();\n  const formRef = useRef<HTMLFormElement>(null);\n  const [status, setStatus] = useState<\"idle\" | \"sending\" | \"sent\">(\"idle\");\n  const [errors, setErrors] = useState<Errors>({});\n  const [topic, setTopic] = useState(topics[0] ?? \"\");\n  const [sentName, setSentName] = useState(\"\");\n\n  const fieldId = (name: keyof ContactValues) => `${id}-${name}`;\n  const errorId = (name: keyof ContactValues) => `${id}-${name}-error`;\n\n  const handleSubmit = async (event: FormEvent<HTMLFormElement>) => {\n    event.preventDefault();\n    const data = new FormData(event.currentTarget);\n    const values: ContactValues = {\n      name: String(data.get(\"name\") ?? \"\"),\n      email: String(data.get(\"email\") ?? \"\"),\n      company: String(data.get(\"company\") ?? \"\"),\n      topic,\n      message: String(data.get(\"message\") ?? \"\"),\n    };\n\n    const nextErrors = validate(values);\n    setErrors(nextErrors);\n    const firstInvalid = Object.keys(nextErrors)[0] as keyof ContactValues | undefined;\n    if (firstInvalid) {\n      formRef.current\n        ?.querySelector<HTMLElement>(`#${CSS.escape(fieldId(firstInvalid))}`)\n        ?.focus();\n      return;\n    }\n\n    setStatus(\"sending\");\n    try {\n      await onSubmit(values);\n      setSentName(values.name.trim().split(\" \")[0]);\n      setStatus(\"sent\");\n    } catch {\n      setStatus(\"idle\");\n    }\n  };\n\n  const clearError = (name: keyof ContactValues) => {\n    if (errors[name]) setErrors((current) => ({ ...current, [name]: undefined }));\n  };\n\n  const fieldProps = (name: keyof ContactValues) => ({\n    id: fieldId(name),\n    name,\n    \"aria-invalid\": errors[name] ? true : undefined,\n    \"aria-describedby\": errors[name] ? errorId(name) : undefined,\n    onChange: () => clearError(name),\n  });\n\n  const errorText = (name: keyof ContactValues) =>\n    errors[name] ? (\n      <p id={errorId(name)} className=\"text-destructive text-xs\">\n        {errors[name]}\n      </p>\n    ) : null;\n\n  return (\n    <section\n      data-slot=\"contact-block\"\n      aria-labelledby={`${id}-title`}\n      className={cn(\"bg-background text-foreground w-full\", className)}\n      {...props}\n    >\n      <div className=\"mx-auto max-w-6xl px-6 py-20 md:py-28\">\n        <div className=\"grid gap-14 md:grid-cols-12 md:gap-8\">\n          <div className=\"md:col-span-5\">\n            <p className=\"text-muted-foreground font-mono text-xs tracking-wider uppercase\">\n              {eyebrow}\n            </p>\n            <h2\n              id={`${id}-title`}\n              className=\"mt-4 max-w-md text-3xl font-semibold tracking-tight text-balance md:text-5xl\"\n            >\n              {title}\n            </h2>\n            <p className=\"text-muted-foreground mt-5 max-w-sm text-sm leading-relaxed\">\n              {intro}\n            </p>\n\n            <dl className=\"mt-12 divide-y border-y\">\n              {channels.map((channel) => (\n                <div key={channel.label} className=\"grid grid-cols-3 gap-4 py-5\">\n                  <dt className=\"text-muted-foreground font-mono text-xs tracking-wider uppercase\">\n                    {channel.label}\n                  </dt>\n                  <dd className=\"col-span-2 text-sm\">\n                    {channel.href ? (\n                      <a\n                        href={channel.href}\n                        className=\"group decoration-primary inline-flex items-center gap-1 rounded-sm font-medium underline-offset-4 outline-none hover:underline focus-visible:ring-2 focus-visible:ring-ring\"\n                      >\n                        {channel.value}\n                        <ArrowUpRight\n                          aria-hidden=\"true\"\n                          className=\"text-muted-foreground size-3.5 transition-transform group-hover:-translate-y-0.5 group-hover:translate-x-0.5 motion-reduce:transition-none\"\n                        />\n                      </a>\n                    ) : (\n                      <span className=\"font-medium\">{channel.value}</span>\n                    )}\n                    {channel.detail ? (\n                      <p className=\"text-muted-foreground mt-1 leading-relaxed\">\n                        {channel.detail}\n                      </p>\n                    ) : null}\n                  </dd>\n                </div>\n              ))}\n            </dl>\n\n            <p className=\"mt-6 flex items-center gap-2 text-sm\">\n              <span aria-hidden=\"true\" className=\"bg-primary size-1.5\" />\n              {responseNote}\n            </p>\n          </div>\n\n          <div className=\"md:col-span-6 md:col-start-7\">\n            <div aria-live=\"polite\" role=\"status\">\n              {status === \"sent\" ? (\n                <div className=\"border-t pt-6\">\n                  <p className=\"text-muted-foreground font-mono text-xs tracking-wider uppercase\">\n                    Message received\n                  </p>\n                  <p className=\"mt-4 text-2xl font-semibold tracking-tight\">\n                    Thanks{sentName ? `, ${sentName}` : \"\"}. It&apos;s in our inbox.\n                  </p>\n                  <p className=\"text-muted-foreground mt-3 max-w-prose text-sm leading-relaxed\">\n                    {responseNote} If it&apos;s urgent, reply to the confirmation email and\n                    mark the subject with [urgent].\n                  </p>\n                  <Button\n                    type=\"button\"\n                    variant=\"outline\"\n                    className=\"mt-8\"\n                    onClick={() => {\n                      setStatus(\"idle\");\n                      setErrors({});\n                    }}\n                  >\n                    Send another message\n                  </Button>\n                </div>\n              ) : null}\n            </div>\n\n            {status !== \"sent\" ? (\n              <form\n                ref={formRef}\n                noValidate\n                onSubmit={handleSubmit}\n                aria-busy={status === \"sending\"}\n                className=\"grid gap-6 border-t pt-6\"\n              >\n                <div className=\"grid gap-6 sm:grid-cols-2\">\n                  <div className=\"grid gap-2\">\n                    <Label htmlFor={fieldId(\"name\")}>Name</Label>\n                    <Input {...fieldProps(\"name\")} autoComplete=\"name\" required />\n                    {errorText(\"name\")}\n                  </div>\n                  <div className=\"grid gap-2\">\n                    <Label htmlFor={fieldId(\"email\")}>Email</Label>\n                    <Input\n                      {...fieldProps(\"email\")}\n                      type=\"email\"\n                      autoComplete=\"email\"\n                      required\n                    />\n                    {errorText(\"email\")}\n                  </div>\n                </div>\n\n                <div className=\"grid gap-2\">\n                  <Label htmlFor={fieldId(\"company\")}>\n                    Company{\" \"}\n                    <span className=\"text-muted-foreground font-normal\">(optional)</span>\n                  </Label>\n                  <Input {...fieldProps(\"company\")} autoComplete=\"organization\" />\n                </div>\n\n                <fieldset className=\"grid gap-3\">\n                  <legend className=\"mb-3 text-sm leading-none font-medium\">Topic</legend>\n                  <RadioGroup\n                    id={fieldId(\"topic\")}\n                    value={topic}\n                    onValueChange={(value) => {\n                      setTopic(value);\n                      clearError(\"topic\");\n                    }}\n                    aria-invalid={errors.topic ? true : undefined}\n                    aria-describedby={errors.topic ? errorId(\"topic\") : undefined}\n                    className=\"grid grid-cols-2 gap-0 border-t border-l\"\n                  >\n                    {topics.map((option, index) => {\n                      const optionId = `${id}-topic-${index}`;\n                      return (\n                        <Label\n                          key={option}\n                          htmlFor={optionId}\n                          className=\"has-[[data-state=checked]]:bg-muted cursor-pointer gap-3 border-r border-b px-4 py-3 font-normal\"\n                        >\n                          <RadioGroupItem id={optionId} value={option} />\n                          {option}\n                        </Label>\n                      );\n                    })}\n                  </RadioGroup>\n                  {errorText(\"topic\")}\n                </fieldset>\n\n                <div className=\"grid gap-2\">\n                  <Label htmlFor={fieldId(\"message\")}>Message</Label>\n                  <Textarea\n                    {...fieldProps(\"message\")}\n                    rows={6}\n                    required\n                    placeholder=\"What are you working on, and when does it need to ship?\"\n                  />\n                  {errorText(\"message\")}\n                </div>\n\n                <div className=\"flex flex-wrap items-center justify-between gap-4 border-t pt-6\">\n                  <p className=\"text-muted-foreground max-w-xs text-xs leading-relaxed\">\n                    We only use your details to reply. Nothing goes on a mailing list.\n                  </p>\n                  <Button type=\"submit\" disabled={status === \"sending\"}>\n                    {status === \"sending\" ? (\n                      <>\n                        <Loader2 aria-hidden=\"true\" className=\"animate-spin\" />\n                        Sending…\n                      </>\n                    ) : (\n                      \"Send message\"\n                    )}\n                  </Button>\n                </div>\n              </form>\n            ) : null}\n          </div>\n        </div>\n      </div>\n    </section>\n  );\n}\n\nexport { ContactBlock };\n"
    }
  ],
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "button",
    "input",
    "label",
    "radio-group",
    "textarea"
  ]
}
