import { useState, useEffect } from 'react'; import { X, ArrowRight, Sprout, Home } from 'lucide-react'; import { Batch, batchesApi } from '../lib/batchesApi'; import { Room, roomsApi } from '../lib/roomsApi'; interface TransitionModalProps { batch: Batch; onClose: () => void; onSuccess: () => void; } const STAGES = [ { id: 'CLONE_IN', label: 'Clone In' }, { id: 'VEGETATIVE', label: 'Vegetative' }, { id: 'FLOWERING', label: 'Flowering' }, { id: 'HARVEST', label: 'Harvest' }, { id: 'DRYING', label: 'Drying' }, { id: 'CURING', label: 'Curing' }, { id: 'FINISHED', label: 'Finished' } ]; export default function BatchTransitionModal({ batch, onClose, onSuccess }: TransitionModalProps) { const [rooms, setRooms] = useState([]); const [targetStage, setTargetStage] = useState(batch.stage); const [targetRoomId, setTargetRoomId] = useState(batch.roomId || ''); const [metadata, setMetadata] = useState({ plantCount: batch.plantCount, notes: '' }); useEffect(() => { roomsApi.getAll().then(setRooms); // Auto-select next stage const currentIndex = STAGES.findIndex(s => s.id === batch.stage); if (currentIndex !== -1 && currentIndex < STAGES.length - 1) { setTargetStage(STAGES[currentIndex + 1].id as any); } }, [batch]); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); try { await batchesApi.update(batch.id, { stage: targetStage, roomId: targetRoomId, plantCount: metadata.plantCount }); onSuccess(); onClose(); } catch (error) { console.error('Failed to transition batch', error); } }; return (

Transition Batch

{batch.name}
{STAGES.find(s => s.id === batch.stage)?.label} {STAGES.find(s => s.id === targetStage)?.label}
setMetadata({ ...metadata, plantCount: parseInt(e.target.value) || 0 })} className="w-full p-3 rounded-lg bg-[var(--color-bg-elevated)] border border-[var(--color-border-default)] dark:text-white" />
); }