import { Card, CardContent } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Textarea } from '@/components/ui/textarea'; import React, { useEffect, useState } from 'react'; import { useSectionEditor } from '../context'; import ArrayFields from './array'; import Contents from './contents'; interface FieldsProps { field: PropertyField; onChange: (value: any) => void; } const Fields = ({ field, onChange }: FieldsProps) => { const { section } = useSectionEditor(); // Local state for basic field types to handle immediate UI updates const [localValue, setLocalValue] = useState(field.value || ''); // Update local state when field.value changes from parent useEffect(() => { setLocalValue(field.value || ''); }, [field.value, field.type]); const handleInputChange = (e: React.ChangeEvent) => { const { value, type } = e.target as HTMLInputElement; if (type === 'checkbox') { const checked = (e.target as HTMLInputElement).checked; setLocalValue(checked); onChange(checked); return; } // Update local state immediately for better UX setLocalValue(value); // Notify parent component onChange(value); }; const handleFileChange = (e: React.ChangeEvent) => { const file = e.target.files?.[0] || null; setLocalValue(file); onChange(file); }; // Render different form elements based on field type const renderField = () => { switch (field.type) { case 'contents': return ; case 'text': case 'url': return ; case 'textarea': return