| 51 | const [isSubmitting, setIsSubmitting] = useState(false); |
| 52 | |
| 53 | const toggleChoice = (qIdx: number, choice: string) => { |
| 54 | if (isResolved || isSubmitting || !onSubmit) return; |
| 55 | setSelectedChoices(prev => { |
| 56 | const next = prev.map(s => [...s]); |
| 57 | const q = questions[qIdx]; |
| 58 | const isMultiple = q.multiple ?? false; |
| 59 | if (next[qIdx].includes(choice)) { |
| 60 | next[qIdx] = next[qIdx].filter(c => c !== choice); |
| 61 | } else if (isMultiple) { |
| 62 | next[qIdx] = [...next[qIdx], choice]; |
| 63 | } else { |
| 64 | // Single-select: deselect others |
| 65 | next[qIdx] = [choice]; |
| 66 | } |
| 67 | return next; |
| 68 | }); |
| 69 | }; |
| 70 | |
| 71 | const setFreeText = (qIdx: number, value: string) => { |
| 72 | setFreeTextAnswers(prev => { |