"use client"; import type { QuestionField } from "@/lib/schema-adapter"; import { useQuestionAnswers } from "./question-answer-storage"; import QuestionTitle from "./question-title"; type QuestionCheckboxProps = { question: QuestionField; disabled?: boolean; }; export function QuestionCheckbox({ question, disabled, }: QuestionCheckboxProps) { const options = question.options || []; const { getAnswerValue, setAnswerValue } = useQuestionAnswers(); const rawValue = getAnswerValue(question); const value = Array.isArray(rawValue) ? rawValue : rawValue ? [String(rawValue)] : []; if (options.length === 0) { return null; } const toggleOption = (optionId: string) => { let nextValue: string[]; if (value.includes(optionId)) { nextValue = value.filter((v) => v !== optionId); } else { nextValue = [...value, optionId]; } setAnswerValue( question, nextValue.length > 0 ? nextValue : null, ); }; const isShortOptions = options.length <= 4 && options.every((opt) => opt.label.length <= 15); return (