import React from 'react'
import { Text } from 'react-native'
import Checkbox from '../checkbox/Checkbox'
import DatePicker from '../datePicker/DatePicker'
import DropdownMaterial from '../dropdownMaterial/DropdownMaterial'
import Input from '../input/Input'
import RadioGroup from '../radioGroup'
import styles from './styles'
import { IFormFieldProps } from './types'
const FormField = ({
id,
fieldType,
error,
dropdownProps,
inputProps,
title,
checkboxProps,
datePickerProps,
radioProps,
headerStyle,
titleStyle,
textStyle,
}: IFormFieldProps) => {
switch (fieldType) {
case 'input':
return (
)
case 'dropdown':
// Special handling for multi-select dropdown
if (dropdownProps?.isMultiSelect && dropdownProps.selectedOptions) {
// For multi-select, we create a display string from selected options
const selectedText =
dropdownProps.selectedOptions.length > 0
? dropdownProps.selectedOptions.map((item) => item.label).join(', ')
: `Select ${dropdownProps?.style?.label?.text || 'items'}`
// Use a fake selectedOption for the display
const displayOption = {
value: '',
label: selectedText,
}
// Return with special multi-select handling
return (
dropdownProps.onSelectOption(id!, item)}
materialInputProps={{
label: dropdownProps?.style?.label?.text || 'Select Multiple',
error: error,
}}
/>
)
} else {
// Standard single-select dropdown
return (
dropdownProps!.onSelectOption(id!, item)}
materialInputProps={{
label: dropdownProps?.style?.label?.text || 'Select',
error: error,
}}
/>
)
}
case 'title':
return {title}
case 'header':
return {title}
case 'text':
return {title}
case 'checkbox':
return (
{
checkboxProps!.onPress(id!)
}}
styles={checkboxProps?.styles}
customTextComp={checkboxProps?.customTextComp}
/>
)
case 'datePicker':
return (
)
case 'radio':
return (
{
// Just call the function directly since we're using non-null assertion
radioProps!.onValueChange(value)
}}
label={radioProps?.label}
error={error}
styles={radioProps?.styles}
/>
)
}
}
export default FormField