import { html, useState } from '../lib/preact.js'; import { getStatusMeta } from '../utils/status.js'; import { OptionButton } from './OptionButton.js'; export function QuestionBlock({ questions, sessionId, status, onRespond }) { const [freeformText, setFreeformText] = useState(''); const [focused, setFocused] = useState(false); const meta = getStatusMeta(status); if (!questions || questions.length === 0) return null; // Only show the first question (sequential, not parallel) const question = questions[0]; const remainingCount = questions.length - 1; const options = question.options || []; const handleOptionClick = (optionLabel) => { onRespond(sessionId, optionLabel, false, options.length); }; const handleFreeformSubmit = (e) => { e.preventDefault(); e.stopPropagation(); if (freeformText.trim()) { onRespond(sessionId, freeformText.trim(), true, options.length); setFreeformText(''); } }; return html`
e.stopPropagation()}> ${question.header && html` ${question.header} `}

${question.question || question.text}

${options.length > 0 && html`
${options.map((opt, i) => html` <${OptionButton} key=${i} number=${i + 1} label=${opt.label || opt} description=${opt.description} onClick=${() => handleOptionClick(opt.label || opt)} /> `)}
`}