'use client'
import type { ReactNode } from 'react'
import type { QuestionOption } from '@/lib/types'
interface CheckboxGroupProps {
name: string
legend: ReactNode
options: QuestionOption[]
value: string[]
maxSelect: number | null
required: boolean
onChange: (value: string[]) => void
error?: string
}
export function CheckboxGroup({
name,
legend,
options,
value,
maxSelect,
required,
onChange,
error,
}: CheckboxGroupProps) {
const atLimit = maxSelect !== null && value.length >= maxSelect
function toggle(optValue: string) {
if (value.includes(optValue)) {
onChange(value.filter((v) => v !== optValue))
} else if (!atLimit) {
onChange([...value, optValue])
}
}
return (
)
}