import { useCallback } from 'react' import { useTranslation } from 'react-i18next' import { useEmbeddedChatbotContext } from '../context' import Input from './form-input' import { PortalSelect } from '@/app/components/base/select' const Form = () => { const { t } = useTranslation() const { inputsForms, newConversationInputs, handleNewConversationInputsChange, isMobile, } = useEmbeddedChatbotContext() const handleFormChange = useCallback((variable: string, value: string) => { handleNewConversationInputsChange({ ...newConversationInputs, [variable]: value, }) }, [newConversationInputs, handleNewConversationInputsChange]) const renderField = (form: any) => { const { label, required, variable, options, } = form if (form.type === 'text-input' || form.type === 'paragraph') { return ( ) } if (form.type === 'number') { return ( handleFormChange(variable, e.target.value)} placeholder={`${label}${!required ? `(${t('appDebug.variableTable.optional')})` : ''}`} /> ) } return ( ({ value: option, name: option }))} onSelect={item => handleFormChange(variable, item.value as string)} placeholder={`${label}${!required ? `(${t('appDebug.variableTable.optional')})` : ''}`} /> ) } if (!inputsForms.length) return null return ( { inputsForms.map(form => ( {form.label} {renderField(form)} )) } ) } export default Form