import React, { useState, useEffect } from 'react'; import { Chemical } from '../types'; import { X } from 'lucide-react'; interface ChemicalFormProps { chemical?: Chemical | null; onSave: (chemical: Omit) => void; onCancel: () => void; } const ChemicalForm: React.FC = ({ chemical, onSave, onCancel }) => { const [formData, setFormData] = useState({ name: '', brand: '', type: 'pesticide' as Chemical['type'], activeIngredient: '', concentration: '', targetPests: '', applicationMethod: '', safetyPeriod: '', notes: '' }); useEffect(() => { if (chemical) { setFormData({ name: chemical.name, brand: chemical.brand || '', type: chemical.type, activeIngredient: chemical.activeIngredient || '', concentration: chemical.concentration || '', targetPests: chemical.targetPests || '', applicationMethod: chemical.applicationMethod || '', safetyPeriod: chemical.safetyPeriod?.toString() || '', notes: chemical.notes || '' }); } }, [chemical]); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); onSave({ ...formData, brand: formData.brand || undefined, activeIngredient: formData.activeIngredient || undefined, concentration: formData.concentration || undefined, targetPests: formData.targetPests || undefined, applicationMethod: formData.applicationMethod || undefined, safetyPeriod: formData.safetyPeriod ? parseInt(formData.safetyPeriod) : undefined, notes: formData.notes || undefined }); }; const handleChange = (e: React.ChangeEvent) => { const { name, value } = e.target; setFormData(prev => ({ ...prev, [name]: value })); }; return (

{chemical ? 'Сохранить' : 'Добавить'}