{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "question-card",
  "title": "QuestionCard",
  "description": "When the agent needs information rather than permission.",
  "registryDependencies": [
    "https://creance.pages.dev/r/button.json",
    "https://creance.pages.dev/r/creance-base.json",
    "https://creance.pages.dev/r/textarea.json"
  ],
  "files": [
    {
      "path": "question-card/QuestionCard.css",
      "content": ".cr-question {\n  display: grid;\n  gap: var(--cr-space-3);\n  margin: 0;\n  padding: var(--cr-space-6);\n  border-radius: var(--cr-radius-xl);\n  color: var(--cr-color-text-default);\n  font-family: var(--cr-font-family-sans);\n  font-size: var(--cr-font-size-md);\n}\n\n.cr-question__who {\n  color: var(--cr-color-text-muted);\n  font-size: var(--cr-font-size-sm);\n}\n\n.cr-question__title {\n  margin: 0;\n  font-family: var(--cr-font-family-display);\n  font-size: var(--cr-font-size-2xl);\n  font-weight: var(--cr-font-weight-bold);\n  letter-spacing: var(--cr-font-tracking-title);\n  line-height: 1.2;\n}\n\n.cr-question[data-answered] .cr-question__title {\n  font-size: var(--cr-font-size-lg);\n  font-weight: var(--cr-font-weight-semibold);\n}\n\n.cr-question__answer {\n  font-weight: var(--cr-font-weight-semibold);\n}\n\n.cr-question__options {\n  display: grid;\n  gap: var(--cr-space-2);\n  margin: 0;\n  padding: 0;\n  border: 0;\n}\n\n.cr-question__option {\n  display: flex;\n  gap: var(--cr-space-3);\n  padding: 14px var(--cr-space-4);\n  border-radius: 14px;\n  background: var(--cr-color-glass-tile);\n  cursor: pointer;\n}\n\n.cr-question__option:has(:checked) {\n  background: var(--cr-color-glass-popover);\n  box-shadow: 0 0 0 1.5px var(--cr-color-ink-bg);\n}\n\n.cr-question__option:has(:focus-visible) {\n  outline: var(--cr-focus-width) solid var(--cr-color-focus);\n  outline-offset: var(--cr-focus-offset);\n}\n\n.cr-question__option input {\n  flex: none;\n  width: 20px;\n  height: 20px;\n  margin: 1px 0 0;\n  accent-color: var(--cr-color-ink-bg);\n}\n\n.cr-question__option input:focus-visible {\n  outline: none;\n}\n\n.cr-question__option-text {\n  display: grid;\n  gap: 2px;\n  font-weight: var(--cr-font-weight-semibold);\n}\n\n.cr-question__option-description {\n  color: var(--cr-color-text-muted);\n  font-size: var(--cr-font-size-sm);\n  font-weight: var(--cr-font-weight-regular);\n}\n\n.cr-question__free {\n  display: grid;\n  gap: var(--cr-space-2);\n}\n\n.cr-question__free-label {\n  font-size: var(--cr-font-size-sm);\n  font-weight: var(--cr-font-weight-semibold);\n}\n\n.cr-question__note {\n  margin: 0;\n  color: var(--cr-color-text-muted);\n  font-size: var(--cr-font-size-sm);\n}\n\n.cr-question__actions {\n  display: flex;\n  flex-wrap: wrap;\n  gap: var(--cr-space-2);\n}\n",
      "type": "registry:file",
      "target": "@components/creance/question-card/QuestionCard.css"
    },
    {
      "path": "question-card/QuestionCard.tsx",
      "content": "'use client';\n\nimport { useId, useState, type ReactNode } from 'react';\nimport { Button } from '@/components/creance/button/Button';\nimport { Textarea } from '@/components/creance/textarea/Textarea';\nimport { cx } from '@/lib/creance/cx';\nimport './QuestionCard.css';\n\nexport interface QuestionOption {\n  value: string;\n  label: string;\n  description?: ReactNode;\n}\n\nexport interface QuestionCardProps {\n  agentName: string;\n  question: string;\n  /** Answers the agent can offer. Leave out for a free-text question. */\n  options?: QuestionOption[];\n  /** Add \"Something else\" with a text box. Default true when there are options. */\n  allowOther?: boolean;\n  /** The option the agent would pick, pre-selected and said openly. */\n  defaultValue?: string;\n  /** Names the option group. Default \"Answer\". */\n  optionsLabel?: string;\n  /** What happens if nobody answers: \"If no one answers in 30 minutes, Data Loader will pause, not guess.\" */\n  timeoutNote?: ReactNode;\n  onAnswer: (answer: string) => void;\n  /** Shows \"Ask me later\". */\n  onDefer?: () => void;\n  /** Once answered, the card shows the answer instead of the form. */\n  answer?: string;\n  headingLevel?: 2 | 3 | 4;\n  className?: string;\n}\n\n/** When the agent needs information rather than permission: options when it has them, free text when not. */\nexport function QuestionCard({\n  agentName,\n  question,\n  options,\n  allowOther = !!options?.length,\n  defaultValue,\n  optionsLabel = 'Answer',\n  timeoutNote,\n  onAnswer,\n  onDefer,\n  answer,\n  headingLevel = 3,\n  className,\n}: QuestionCardProps) {\n  const id = useId();\n  const H = `h${headingLevel}` as const;\n  const [choice, setChoice] = useState(defaultValue ?? options?.[0]?.value ?? '');\n  const [text, setText] = useState('');\n  const other = !options?.length || choice === '__other';\n  const value = other ? text.trim() : options!.find((o) => o.value === choice)?.label ?? choice;\n\n  if (answer !== undefined) {\n    return (\n      <section aria-labelledby={id} className={cx('cr-question cr-surface', className)} data-answered=\"\">\n        <span className=\"cr-question__who\">{agentName} asked</span>\n        <H id={id} className=\"cr-question__title\">\n          {question}\n        </H>\n        <span className=\"cr-question__answer\">You answered {answer}</span>\n      </section>\n    );\n  }\n\n  return (\n    <form\n      aria-labelledby={id}\n      className={cx('cr-question cr-glass', className)}\n      onSubmit={(e) => {\n        e.preventDefault();\n        if (value) onAnswer(value);\n      }}\n    >\n      <span className=\"cr-question__who\">{agentName} is asking</span>\n      <H id={id} className=\"cr-question__title\">\n        {question}\n      </H>\n      {options?.length ? (\n        <fieldset className=\"cr-question__options\">\n          <legend className=\"cr-visually-hidden\">{optionsLabel}</legend>\n          {[...options, ...(allowOther ? [{ value: '__other', label: 'Something else' } as QuestionOption] : [])].map((o) => (\n            <label key={o.value} className=\"cr-question__option\">\n              <input type=\"radio\" name={id} value={o.value} checked={choice === o.value} onChange={() => setChoice(o.value)} />\n              <span className=\"cr-question__option-text\">\n                <span>{o.label}</span>\n                {o.description && <span className=\"cr-question__option-description\">{o.description}</span>}\n              </span>\n            </label>\n          ))}\n        </fieldset>\n      ) : null}\n      {other && (\n        <div className=\"cr-question__free\">\n          <label htmlFor={`${id}-text`} className=\"cr-question__free-label\">\n            Your answer\n          </label>\n          <Textarea id={`${id}-text`} rows={3} value={text} onChange={(e) => setText(e.currentTarget.value)} />\n        </div>\n      )}\n      {timeoutNote && <p className=\"cr-question__note\">{timeoutNote}</p>}\n      <div className=\"cr-question__actions\">\n        <Button type=\"submit\" variant=\"primary\" disabled={!value}>\n          {options?.length ? 'Answer' : 'Send answer'}\n        </Button>\n        {onDefer && <Button onClick={onDefer}>Ask me later</Button>}\n      </div>\n    </form>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/creance/question-card/QuestionCard.tsx"
    }
  ],
  "categories": [
    "organism",
    "agent"
  ],
  "type": "registry:ui"
}