import { useState, useEffect } from 'react'; import { batchesApi, Batch } from '../lib/batchesApi'; import { touchPointsApi } from '../lib/touchPointsApi'; import { Droplets, Utensils, Scissors, Dumbbell, Search, ShieldCheck, Shovel, Sprout, Fingerprint, ChevronLeft, Loader2 } from 'lucide-react'; import { PageHeader, EmptyState, CardSkeleton } from '../components/ui/LinearPrimitives'; import { useToast } from '../context/ToastContext'; export default function TouchPointPage() { const { addToast } = useToast(); 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); 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, accent: 'accent' as const }, { id: 'FEED', label: 'Feed', icon: Utensils, accent: 'success' as const }, { id: 'PRUNE', label: 'Prune', icon: Scissors, accent: 'warning' as const }, { id: 'TRAIN', label: 'Train', icon: Dumbbell, accent: 'accent' as const }, { id: 'INSPECT', label: 'Inspect', icon: Search, accent: 'default' as const }, { id: 'IPM', label: 'IPM', icon: ShieldCheck, accent: 'destructive' as const }, { id: 'TRANSPLANT', label: 'Transplant', icon: Shovel, accent: 'warning' as const }, { id: 'HARVEST', label: 'Harvest', icon: Sprout, accent: 'success' as const }, ]; const getAccentClasses = (accent: string) => { switch (accent) { case 'success': return 'bg-success-muted text-success border-success/20 hover:border-success/40'; case 'warning': return 'bg-warning-muted text-warning border-warning/20 hover:border-warning/40'; case 'destructive': return 'bg-destructive-muted text-destructive border-destructive/20 hover:border-destructive/40'; case 'accent': return 'bg-accent-muted text-accent border-accent/20 hover:border-accent/40'; default: return 'bg-tertiary text-secondary border-default hover:border-strong'; } }; const handleSubmit = async () => { if (!selectedBatch || !actionType) return; setSubmitting(true); try { await touchPointsApi.create({ batchId: selectedBatch.id, type: actionType as any, notes, }); addToast('Touch point recorded!', 'success'); setActionType(null); setNotes(''); } catch (err) { addToast('Failed to record', 'error'); } finally { setSubmitting(false); } }; if (isLoading) { return (
{Array.from({ length: 4 }).map((_, i) => )}
); } return (
{/* Step 1: Select Batch */} {!selectedBatch ? (

Select Batch

{batches.length === 0 ? ( ) : (
{batches.map(batch => ( ))}
)}
) : !actionType ? ( /* Step 2: Select Action */
{selectedBatch.name?.replace('[DEMO] ', '')}
Select an action
{selectedBatch.strain}
{actions.map(action => ( ))}
) : ( /* Step 3: Confirm */
{(() => { const action = actions.find(a => a.id === actionType); const Icon = action?.icon || Fingerprint; return ; })()} {actions.find(a => a.id === actionType)?.label} for {selectedBatch.name?.replace('[DEMO] ', '')}