'use client' import { useState } from 'react' import { VariableDebt } from '@/lib/types' import { cn } from '@/lib/utils' interface VariableDebtFormProps { initialData?: Partial onSubmit: (data: Omit) => void onCancel: () => void } const categories = [ { value: 'shopping', label: 'Compras' }, { value: 'food', label: 'Comida' }, { value: 'entertainment', label: 'Entretenimiento' }, { value: 'health', label: 'Salud' }, { value: 'transport', label: 'Transporte' }, { value: 'other', label: 'Otro' }, ] as const export function VariableDebtForm({ initialData, onSubmit, onCancel }: VariableDebtFormProps) { const [formData, setFormData] = useState({ name: initialData?.name || '', amount: initialData?.amount || 0, date: initialData?.date || new Date().toISOString().split('T')[0], category: initialData?.category || 'other', notes: initialData?.notes || '', }) const [errors, setErrors] = useState>({}) const validate = (): boolean => { const newErrors: Record = {} if (!formData.name.trim()) { newErrors.name = 'El nombre es requerido' } if (formData.amount <= 0) { newErrors.amount = 'El monto debe ser mayor a 0' } if (!formData.date) { newErrors.date = 'La fecha es requerida' } setErrors(newErrors) return Object.keys(newErrors).length === 0 } const handleSubmit = (e: React.FormEvent) => { e.preventDefault() if (validate()) { onSubmit(formData) } } const updateField = ( field: K, value: typeof formData[K] ) => { setFormData((prev) => ({ ...prev, [field]: value })) if (errors[field]) { setErrors((prev) => { const newErrors = { ...prev } delete newErrors[field] return newErrors }) } } return (
updateField('name', e.target.value)} className={cn( 'w-full px-3 py-2 bg-slate-800 border rounded-lg text-white placeholder-slate-500', 'focus:outline-none focus:ring-2 focus:ring-blue-500/50 focus:border-blue-500', errors.name ? 'border-red-500' : 'border-slate-600' )} placeholder="Ej: Supermercado, Cena, etc." /> {errors.name &&

{errors.name}

}
updateField('amount', parseFloat(e.target.value) || 0)} className={cn( 'w-full px-3 py-2 bg-slate-800 border rounded-lg text-white placeholder-slate-500', 'focus:outline-none focus:ring-2 focus:ring-blue-500/50 focus:border-blue-500', errors.amount ? 'border-red-500' : 'border-slate-600' )} placeholder="0.00" /> {errors.amount &&

{errors.amount}

}
updateField('date', e.target.value)} className={cn( 'w-full px-3 py-2 bg-slate-800 border rounded-lg text-white', 'focus:outline-none focus:ring-2 focus:ring-blue-500/50 focus:border-blue-500', errors.date ? 'border-red-500' : 'border-slate-600' )} /> {errors.date &&

{errors.date}

}