import React from 'react' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { Checkbox } from '@/components/ui/checkbox' import type { BackendOptions } from '@/schemas/instanceOptions' import { getBackendFieldType, basicBackendFieldsConfig } from '@/lib/zodFormUtils' interface BackendFormFieldProps { fieldKey: keyof BackendOptions value: string | number | boolean | string[] | undefined onChange: (key: string, value: string | number | boolean | string[] | undefined) => void } const BackendFormField: React.FC = ({ fieldKey, value, onChange }) => { // Get configuration for basic fields, or use field name for advanced fields const config = basicBackendFieldsConfig[fieldKey as string] || { label: fieldKey } // Get type from Zod schema const fieldType = getBackendFieldType(fieldKey) const handleChange = (newValue: string | number | boolean | string[] | undefined) => { onChange(fieldKey as string, newValue) } const renderField = () => { switch (fieldType) { case 'boolean': return (
handleChange(checked)} />
) case 'number': return (
{ const numValue = e.target.value ? parseFloat(e.target.value) : undefined // Only update if the parsed value is valid or the input is empty if (e.target.value === '' || (numValue !== undefined && !isNaN(numValue))) { handleChange(numValue) } }} placeholder={config.placeholder} /> {config.description && (

{config.description}

)}
) case 'array': return (
{ const arrayValue = e.target.value ? e.target.value.split(',').map(s => s.trim()).filter(Boolean) : undefined handleChange(arrayValue) }} placeholder="item1, item2, item3" /> {config.description && (

{config.description}

)}

Separate multiple values with commas

) case 'text': default: return (
handleChange(e.target.value || undefined)} placeholder={config.placeholder} /> {config.description && (

{config.description}

)}
) } } return
{renderField()}
} export default BackendFormField