"use client" import { FormField } from "@/types/form" interface FieldEditorProps { field: FormField index: number totalFields: number onUpdate: (updates: Partial) => void onRemove: () => void onMove: (direction: "up" | "down") => void } export default function FieldEditor({ field, index, totalFields, onUpdate, onRemove, onMove, }: FieldEditorProps) { const hasOptions = field.type === "select" || field.type === "radio" || field.type === "checkbox" const addOption = () => { const newOptions = [...(field.options || []), `Option ${(field.options?.length || 0) + 1}`] onUpdate({ options: newOptions }) } const updateOption = (optionIndex: number, value: string) => { const newOptions = [...(field.options || [])] newOptions[optionIndex] = value onUpdate({ options: newOptions }) } const removeOption = (optionIndex: number) => { const newOptions = (field.options || []).filter((_, i) => i !== optionIndex) onUpdate({ options: newOptions }) } const getFieldTypeLabel = (type: string): string => { const labels: Record = { text: "Texte court", textarea: "Texte long", email: "Email", number: "Nombre", phone: "Téléphone", date: "Date", time: "Heure", select: "Liste déroulante", radio: "Choix unique", checkbox: "Choix multiple", } return labels[type] || type } return (
{index + 1} {getFieldTypeLabel(field.type)}
onUpdate({ label: e.target.value })} placeholder="Ex: Quel est votre nom ?" className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-colors" />
{(field.type === "text" || field.type === "textarea" || field.type === "email" || field.type === "number" || field.type === "phone") && (
onUpdate({ placeholder: e.target.value })} placeholder="Texte d'aide affiché dans le champ" className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-colors" />
)} {hasOptions && (
{(field.options || []).map((option, optionIndex) => (
updateOption(optionIndex, e.target.value)} placeholder={`Option ${optionIndex + 1}`} className="flex-1 px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-colors" /> {(field.options?.length || 0) > 1 && ( )}
))}
)}
onUpdate({ required: e.target.checked })} className="w-4 h-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500" />
) }