import { useState, useEffect } from 'react'; import { useParams, useNavigate, Link } from 'react-router-dom'; import { ArrowLeft, Calendar, Droplets, Thermometer, Wind, Zap, Bug, Camera, Activity, TrendingUp, Clock, CheckCircle2, AlertTriangle, Sprout, Sun, History, ClipboardList, ShieldCheck, BarChart3, MoreHorizontal, Download, Plus, Trash2, ExternalLink } from 'lucide-react'; import { batchesApi, Batch } from '../lib/batchesApi'; import { Card } from '../components/ui/card'; import { cn } from '../lib/utils'; import { motion, AnimatePresence } from 'framer-motion'; // Mock sensor data for Sparklines function generateMockData(count: number, min: number, max: number) { return Array.from({ length: count }, (_, i) => ({ value: min + Math.random() * (max - min), })); } export default function BatchDetailPage() { const { id } = useParams<{ id: string }>(); const navigate = useNavigate(); const [batch, setBatch] = useState(null); const [loading, setLoading] = useState(true); const [activeTab, setActiveTab] = useState<'overview' | 'environment' | 'tasks' | 'compliance'>('overview'); useEffect(() => { if (id) { setLoading(true); batchesApi.getById(id) .then(setBatch) .catch((err) => { console.error('Failed to load batch:', err); navigate('/batches'); }) .finally(() => setLoading(false)); } }, [id, navigate]); if (loading) { return (
); } if (!batch) return null; const startDate = new Date(batch.startDate); const daysInCycle = Math.floor((Date.now() - startDate.getTime()) / (1000 * 60 * 60 * 24)); return (
{/* Context Header */}

{batch.name}

{batch.stage}
{batch.strain}
{batch.plantCount} Plants
Cycle Day {daysInCycle}
METRC SYNCED
{/* KPI Strip */}
{/* Main Content Area */}
{/* Vertical Timeline - Left Column */}

Batch Lifecycle

{/* Tabbed Content - Right Column */}
setActiveTab('overview')} /> setActiveTab('environment')} /> setActiveTab('tasks')} /> setActiveTab('compliance')} />
{activeTab === 'overview' && (

Quick Actions

Integration Hub

Recent Activity

{batch.touchPoints?.map(tp => (

{tp.type}

{tp.notes || 'Routine check complete'}

{tp.user?.name}

{new Date(tp.createdAt).toLocaleDateString()}

))}
)} {activeTab === 'environment' && (

Sensor Rollups

Interactive Analytics Terminal Rendering environmental time-series...
)} {activeTab === 'compliance' && (
Compliance OK

No outstanding events detected.

Verified

All labor hours signed off.

Manifest Ready

Export batch certificate of analysis.

Traceability History

{[1, 2, 3].map(i => (
#E-00452-Z Batch Transfer: Veg-1 to Flow-A
))}
)}
); } function KPICard({ label, value, trend, status, icon: Icon }: any) { return (
{label}
{value}
{trend}
); } function TimelineEvent({ status, title, date, desc, icon: Icon }: any) { return (
{title}

{date}

{desc}

); } function TabButton({ active, label, icon: Icon, count, onClick }: any) { return ( ); } function ActionButton({ label, icon: Icon }: any) { return ( ); } function IntegrationItem({ name, status, time }: any) { return (

{name}

{time}

{status}
); } function Layers({ size, className }: any) { return ; } function LayoutDashboard({ size, className }: any) { return ; }