import { useState } from 'react'; import { useForm } from '../../context/FormContext'; import { Plus } from 'lucide-react'; export default function FillBlank({ field, sectionId }) { const { formState, toggleOption, addCustomOption } = useForm(); const [customInput, setCustomInput] = useState(''); const fieldState = formState.sections[sectionId]?.[field.id] || { selected: [], customOptions: [] }; const allOptions = [...(field.options || []), ...(fieldState.customOptions || [])]; const selected = fieldState.selected || []; const filledSentence = field.sentence?.replace( /____________/g, selected.length > 0 ? selected.join(' / ') : '____________' ); const handleAddCustom = () => { if (customInput.trim()) { addCustomOption(sectionId, field.id, customInput.trim()); setCustomInput(''); } }; const handleKeyDown = (e) => { if (e.key === 'Enter') { e.preventDefault(); handleAddCustom(); } }; return (
{field.label}
{field.sentence && (
{filledSentence.split('____________').map((part, i, arr) => ( {part} {i < arr.length - 1 && ( 0 ? 'fill-blank__blank--filled' : ''}`}> {selected.length > 0 ? selected.join(' / ') : '____________'} )} ))}
)}
{allOptions.map(option => ( ))}
setCustomInput(e.target.value)} onKeyDown={handleKeyDown} />
); }