import { useState, useEffect } from 'react'; import { useNavigate } from 'react-router-dom'; import { batchesApi, Batch } from '../lib/batchesApi'; import { touchPointsApi, PlantTouchPoint, IPMSchedule } from '../lib/touchPointsApi'; import { Loader2, Droplets, Utensils, Scissors, Dumbbell, Search, ShieldCheck, Shovel, Sprout } from 'lucide-react'; export default function TouchPointPage() { const navigate = useNavigate(); const [batches, setBatches] = useState([]); const [isLoading, setIsLoading] = useState(true); const [selectedBatch, setSelectedBatch] = useState(null); const [actionType, setActionType] = useState(null); const [notes, setNotes] = useState(''); const [submitting, setSubmitting] = useState(false); // Load active batches useEffect(() => { batchesApi.getAll().then(data => { setBatches(data.filter(b => b.status === 'ACTIVE')); setIsLoading(false); }).catch(err => { console.error(err); setIsLoading(false); }); }, []); const actions = [ { id: 'WATER', label: 'Water', icon: Droplets, color: 'text-blue-500 bg-blue-50 border-blue-200' }, { id: 'FEED', label: 'Feed', icon: Utensils, color: 'text-green-500 bg-green-50 border-green-200' }, { id: 'PRUNE', label: 'Prune', icon: Scissors, color: 'text-amber-500 bg-amber-50 border-amber-200' }, { id: 'TRAIN', label: 'Train', icon: Dumbbell, color: 'text-purple-500 bg-purple-50 border-purple-200' }, { id: 'INSPECT', label: 'Inspect', icon: Search, color: 'text-slate-500 bg-slate-50 border-slate-200' }, { id: 'IPM', label: 'IPM', icon: ShieldCheck, color: 'text-red-500 bg-red-50 border-red-200' }, { id: 'TRANSPLANT', label: 'Transplant', icon: Shovel, color: 'text-orange-500 bg-orange-50 border-orange-200' }, { id: 'HARVEST', label: 'Harvest', icon: Sprout, color: 'text-emerald-500 bg-emerald-50 border-emerald-200' }, ]; const handleSubmit = async () => { if (!selectedBatch || !actionType) return; setSubmitting(true); try { await touchPointsApi.create({ batchId: selectedBatch.id, type: actionType as any, notes, }); // Reset setActionType(null); setNotes(''); alert('Touch point recorded!'); } catch (err) { alert('Failed to record'); } finally { setSubmitting(false); } }; if (isLoading) return
; if (!selectedBatch) { return (

Select Batch

{batches.map(batch => ( ))}
); } if (!actionType) { return (

{selectedBatch.name}

Record Interaction

{actions.map(action => ( ))}
); } return (

{actions.find(a => a.id === actionType)?.label} for {selectedBatch.name}