import { useState } from 'react'; import { X, Save, FileText } from 'lucide-react'; import { taskTemplatesApi, CreateTaskTemplateData, TaskTemplate } from '../lib/taskTemplatesApi'; import { RoomType } from '../lib/roomsApi'; interface TaskTemplateModalProps { template?: TaskTemplate | null; onClose: () => void; onSuccess: () => void; } const ROOM_TYPES: RoomType[] = ['VEG', 'FLOWER', 'DRY', 'CURE', 'MOTHER', 'CLONE', 'FACILITY']; export default function TaskTemplateModal({ template, onClose, onSuccess }: TaskTemplateModalProps) { const [formData, setFormData] = useState({ title: template?.title || '', description: template?.description || '', roomType: template?.roomType || 'VEG', estimatedMinutes: template?.estimatedMinutes || 30, materials: template?.materials || [], recurrence: template?.recurrence || { type: 'manual' } // Default to manual }); const [materialsInput, setMaterialsInput] = useState(template?.materials?.join(', ') || ''); const [isSubmitting, setIsSubmitting] = useState(false); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setIsSubmitting(true); // Parse materials const materials = materialsInput.split(',').map(s => s.trim()).filter(Boolean); try { const payload = { ...formData, materials }; if (template) { await taskTemplatesApi.update(template.id, payload); } else { await taskTemplatesApi.create(payload); } onSuccess(); onClose(); } catch (error) { console.error('Failed to save template', error); } finally { setIsSubmitting(false); } }; return (

{template ? 'Edit Template' : 'New Task Template'}

setFormData({ ...formData, title: e.target.value })} className="w-full p-3 rounded-lg bg-white dark:bg-slate-900 border border-slate-200 dark:border-slate-700 dark:text-white" placeholder="e.g. Daily Veg Watering" required />
setFormData({ ...formData, estimatedMinutes: parseInt(e.target.value) || 0 })} className="w-full p-3 rounded-lg bg-white dark:bg-slate-900 border border-slate-200 dark:border-slate-700 dark:text-white" />