import React from 'react' /** * Renderizador Dinámico de Campos de Respuesta * Renderiza el input apropiado según la configuración de la pregunta */ export function QuestionAnswerInput({ question, value, onChange, onSave }) { const config = question.options || {} const questionType = config.type || question.type // BOOLEAN (2 opciones) if (questionType === 'boolean' && config.choices?.length === 2) { const [choice1, choice2] = config.choices return (
) } // SINGLE CHOICE (selección única) if (questionType === 'single_choice' && config.choices) { return (
{config.choices.map((choice, idx) => ( ))} {config.allow_other && (
)}
) } // MULTIPLE CHOICE (selección múltiple) if (questionType === 'multiple_choice' && config.choices) { const selectedValues = value ? (Array.isArray(value) ? value : value.split(',')) : [] const handleToggle = (choiceValue) => { let newValues if (selectedValues.includes(choiceValue)) { newValues = selectedValues.filter(v => v !== choiceValue) } else { newValues = [...selectedValues, choiceValue] } onChange(newValues.join(',')) onSave?.() } return (
{config.choices.map((choice, idx) => ( ))}
) } // SCALE (escala numérica) if (questionType === 'scale') { const min = config.min || 1 const max = config.max || 5 const step = config.step || 1 const labels = config.labels || {} const options = [] for (let i = min; i <= max; i += step) { options.push(i) } return (
{labels.min && {labels.min}} {labels.max && {labels.max}}
{options.map(num => ( ))}
{value && (
Seleccionado: {value} / {max}
)}
) } // TEXT (texto libre) if (questionType === 'text') { const multiline = config.multiline !== false const maxLength = config.max_length || 500 if (multiline) { return (