{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "answer-form",
  "type": "registry:ui",
  "title": "Answer Form",
  "description": "The answer-form primitive.",
  "dependencies": [],
  "registryDependencies": [
    "https://ui.klarhimmel.com/r/button.json",
    "https://ui.klarhimmel.com/r/input.json",
    "https://ui.klarhimmel.com/r/theme.json",
    "https://ui.klarhimmel.com/r/utils.json"
  ],
  "files": [
    {
      "path": "src/ui/answer-form.tsx",
      "type": "registry:file",
      "target": "components/klarhimmel/ui/answer-form.tsx",
      "content": "import type { ReactNode } from 'react';\nimport { cn } from '../lib/utils';\nimport { Button } from './button';\nimport { Field, Textarea } from './input';\n\nexport interface AnswerFormProps {\n  /** Where the answer is posted. A plain form: it works with no JavaScript, and the server decides what happens next. */\n  action?: string;\n  method?: 'post' | 'get';\n  /** Label of the note. */\n  label?: ReactNode;\n  /** Keep the label for screen readers only, when the item above already says what to write. */\n  labelHidden?: boolean;\n  /** One quiet line under the note, e.g. \"Approving needs no note.\" */\n  hint?: ReactNode;\n  /** Set by the server when it refused the answer (a change asked for with no note): shown under the note, which is marked invalid. */\n  error?: ReactNode;\n  /** The note as it was sent, so a refused answer keeps what was typed. */\n  defaultValue?: string;\n  /** Form field names: the note, and the button that was pressed (its value is 'approve' or 'change'). */\n  noteName?: string;\n  answerName?: string;\n  approveLabel?: ReactNode;\n  changeLabel?: ReactNode;\n  /** Hidden fields sent with the answer: the item's id, a CSRF token. */\n  hidden?: Record<string, string>;\n  disabled?: boolean;\n  className?: string;\n}\n\n/**\n * Answer one item (a deliverable, a draft, a quote) with approve or ask for a change, plus a short note. Server-rendered and\n * JavaScript-free: the two buttons submit the same form with `answer=approve` or `answer=change`. Approve never needs the note;\n * the server refuses a change with no note and renders the form again with `error` and the note kept.\n */\nexport function AnswerForm({\n  action,\n  method = 'post',\n  label = 'What should change?',\n  labelHidden,\n  hint,\n  error,\n  defaultValue,\n  noteName = 'note',\n  answerName = 'answer',\n  approveLabel = 'Approve',\n  changeLabel = 'Ask for a change',\n  hidden,\n  disabled,\n  className,\n}: AnswerFormProps) {\n  return (\n    <form action={action} method={method} className={cn('flex flex-col gap-3', className)}>\n      {hidden && Object.entries(hidden).map(([k, v]) => <input key={k} type=\"hidden\" name={k} value={v} />)}\n      <Field label={label} labelHidden={labelHidden} hint={hint} error={error}>\n        {(p) => <Textarea {...p} name={noteName} rows={3} defaultValue={defaultValue} disabled={disabled} maxLength={2000} />}\n      </Field>\n      <div className=\"flex flex-wrap gap-2\">\n        <Button type=\"submit\" name={answerName} value=\"approve\" disabled={disabled}>{approveLabel}</Button>\n        <Button type=\"submit\" name={answerName} value=\"change\" variant=\"secondary\" disabled={disabled}>{changeLabel}</Button>\n      </div>\n    </form>\n  );\n}\n"
    }
  ]
}
