import React, { useCallback } from 'react'; import { motion } from 'framer-motion'; import { Input } from '../../ui/input'; import { Textarea } from '../../ui/textarea'; import { Checkbox } from '../../ui/checkbox'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../../ui/select'; import Typography from '../../ui/Typography'; import { cn } from '../../../lib/utils'; import { FiInfo, FiAlertCircle } from 'react-icons/fi'; import type { EnhancedRenderConfig } from './types'; interface FormFieldProps { name: string; config: EnhancedRenderConfig; value: unknown; onChange: (value: unknown) => void; error?: string; disabled?: boolean; touched?: boolean; onTouch?: () => void; className?: string; } /** * Renders individual form fields based on configuration */ export function FormField({ name, config, value, onChange, error, disabled = false, touched = false, onTouch, className }: FormFieldProps) { const { fieldType, ui = {}, constraints = {}, options = [], validation = {} } = config; const { label, placeholder, helpText, required, readonly, width = 'full', className: uiClassName } = ui; const handleChange = useCallback((newValue: unknown) => { onChange(newValue); onTouch?.(); }, [onChange, onTouch]); /** * Individual field input component */ const FieldInput: React.FC<{ fieldType: string; value: unknown; onChange: (value: unknown) => void; constraints: any; config: EnhancedRenderConfig; error?: string; disabled?: boolean; readonly?: boolean; placeholder?: string; onTouch?: () => void; uiClassName?: string; label?: string; options?: any[]; }> = ({ fieldType, value, onChange, constraints, config, error, disabled, readonly, placeholder, onTouch, uiClassName, label, options = [] }) => { const baseProps = { disabled: disabled || readonly, className: cn( error && 'border-red-500 focus:border-red-500 focus:ring-red-500', uiClassName ) }; switch (fieldType) { case 'text': { const inputType = constraints.type === 'email' ? 'email' : constraints.type === 'url' ? 'url' : 'text'; return ( onChange(e.target.value)} placeholder={placeholder} minLength={constraints.minLength as number} maxLength={constraints.maxLength as number} pattern={constraints.pattern as string} onBlur={onTouch} /> ); } case 'number': return ( onChange(Number(e.target.value))} placeholder={placeholder} min={constraints.min as number} max={constraints.max as number} step={constraints.step as number} onBlur={onTouch} /> ); case 'textarea': return (