import React, { useState, useEffect } from 'react'; import { Clock, Calendar, ChefHat, TrendingUp, AlertTriangle, CheckCircle, Settings, Plus, BarChart3, Users, Timer, Target, Activity, Zap } from 'lucide-react'; // Import existing complex components import ProductionSchedule from '../../components/ui/ProductionSchedule'; import DemandHeatmap from '../../components/ui/DemandHeatmap'; import { useDashboard } from '../../hooks/useDashboard'; // Types for production management interface ProductionMetrics { efficiency: number; onTimeCompletion: number; wastePercentage: number; energyUsage: number; staffUtilization: number; } interface ProductionBatch { id: string; product: string; batchSize: number; startTime: string; endTime: string; status: 'planned' | 'in_progress' | 'completed' | 'delayed'; assignedStaff: string[]; actualYield: number; expectedYield: number; notes?: string; temperature?: number; humidity?: number; } interface StaffMember { id: string; name: string; role: 'baker' | 'assistant' | 'decorator'; currentTask?: string; status: 'available' | 'busy' | 'break'; efficiency: number; } interface Equipment { id: string; name: string; type: 'oven' | 'mixer' | 'proofer' | 'cooling_rack'; status: 'idle' | 'in_use' | 'maintenance' | 'error'; currentBatch?: string; temperature?: number; maintenanceDue?: string; } const ProductionPage: React.FC = () => { const { todayForecasts, metrics, weather, isLoading } = useDashboard(); const [activeTab, setActiveTab] = useState<'schedule' | 'batches' | 'analytics' | 'staff' | 'equipment'>('schedule'); const [productionMetrics, setProductionMetrics] = useState({ efficiency: 87.5, onTimeCompletion: 94.2, wastePercentage: 3.8, energyUsage: 156.7, staffUtilization: 78.3 }); // Sample production schedule data const [productionSchedule, setProductionSchedule] = useState([ { time: '05:00 AM', items: [ { id: 'prod-1', product: 'Croissants', quantity: 48, priority: 'high' as const, estimatedTime: 180, status: 'in_progress' as const, confidence: 0.92, notes: 'Alta demanda prevista - lote doble' }, { id: 'prod-2', product: 'Pan de molde', quantity: 35, priority: 'high' as const, estimatedTime: 240, status: 'pending' as const, confidence: 0.88 } ], totalTime: 420 }, { time: '08:00 AM', items: [ { id: 'prod-3', product: 'Baguettes', quantity: 25, priority: 'medium' as const, estimatedTime: 200, status: 'pending' as const, confidence: 0.75 }, { id: 'prod-4', product: 'Magdalenas', quantity: 60, priority: 'medium' as const, estimatedTime: 120, status: 'pending' as const, confidence: 0.82 } ], totalTime: 320 } ]); const [productionBatches, setProductionBatches] = useState([ { id: 'batch-1', product: 'Croissants', batchSize: 48, startTime: '05:00', endTime: '08:00', status: 'in_progress', assignedStaff: ['maria-lopez', 'carlos-ruiz'], actualYield: 45, expectedYield: 48, temperature: 180, humidity: 65, notes: 'Masa fermentando correctamente' }, { id: 'batch-2', product: 'Pan de molde', batchSize: 35, startTime: '06:30', endTime: '10:30', status: 'planned', assignedStaff: ['ana-garcia'], actualYield: 0, expectedYield: 35, notes: 'Esperando finalización de croissants' } ]); const [staff, setStaff] = useState([ { id: 'maria-lopez', name: 'María López', role: 'baker', currentTask: 'Preparando croissants', status: 'busy', efficiency: 94.2 }, { id: 'carlos-ruiz', name: 'Carlos Ruiz', role: 'assistant', currentTask: 'Horneando croissants', status: 'busy', efficiency: 87.8 }, { id: 'ana-garcia', name: 'Ana García', role: 'baker', status: 'available', efficiency: 91.5 } ]); const [equipment, setEquipment] = useState([ { id: 'oven-1', name: 'Horno Principal', type: 'oven', status: 'in_use', currentBatch: 'batch-1', temperature: 180, maintenanceDue: '2024-11-15' }, { id: 'mixer-1', name: 'Amasadora Industrial', type: 'mixer', status: 'idle', maintenanceDue: '2024-11-20' }, { id: 'proofer-1', name: 'Fermentadora', type: 'proofer', status: 'in_use', currentBatch: 'batch-2', temperature: 28, maintenanceDue: '2024-12-01' } ]); // Demand heatmap sample data const heatmapData = [ { weekStart: '2024-11-04', days: [ { date: '2024-11-04', demand: 180, isToday: true, products: [ { name: 'Croissants', demand: 48, confidence: 'high' as const }, { name: 'Pan de molde', demand: 35, confidence: 'high' as const }, { name: 'Baguettes', demand: 25, confidence: 'medium' as const }, { name: 'Magdalenas', demand: 32, confidence: 'medium' as const }, ] }, { date: '2024-11-05', demand: 165, isForecast: true, products: [ { name: 'Croissants', demand: 42, confidence: 'high' as const }, { name: 'Pan de molde', demand: 38, confidence: 'medium' as const }, { name: 'Baguettes', demand: 28, confidence: 'medium' as const }, { name: 'Magdalenas', demand: 28, confidence: 'low' as const }, ] }, { date: '2024-11-06', demand: 195, isForecast: true, products: [ { name: 'Croissants', demand: 55, confidence: 'high' as const }, { name: 'Pan de molde', demand: 40, confidence: 'high' as const }, { name: 'Baguettes', demand: 32, confidence: 'medium' as const }, { name: 'Magdalenas', demand: 35, confidence: 'medium' as const }, ] }, { date: '2024-11-07', demand: 220, isForecast: true }, { date: '2024-11-08', demand: 185, isForecast: true }, { date: '2024-11-09', demand: 250, isForecast: true }, { date: '2024-11-10', demand: 160, isForecast: true } ] } ]; const getStatusColor = (status: string) => { switch (status) { case 'planned': return 'bg-blue-100 text-blue-800'; case 'in_progress': return 'bg-yellow-100 text-yellow-800'; case 'completed': return 'bg-green-100 text-green-800'; case 'delayed': return 'bg-red-100 text-red-800'; default: return 'bg-gray-100 text-gray-800'; } }; const getEquipmentStatusColor = (status: Equipment['status']) => { switch (status) { case 'idle': return 'bg-gray-100 text-gray-800'; case 'in_use': return 'bg-green-100 text-green-800'; case 'maintenance': return 'bg-yellow-100 text-yellow-800'; case 'error': return 'bg-red-100 text-red-800'; default: return 'bg-gray-100 text-gray-800'; } }; if (isLoading) { return (
{[...Array(4)].map((_, i) => (
))}
); } return (
{/* Header */}

Centro de Producción

Gestión completa de la producción diaria y planificación inteligente

Eficiencia Hoy
{productionMetrics.efficiency}%
{/* Key Metrics Cards */}

Eficiencia

{productionMetrics.efficiency}%

+2.3% vs ayer

A Tiempo

{productionMetrics.onTimeCompletion}%

Muy bueno

Desperdicio

{productionMetrics.wastePercentage}%

-0.5% vs ayer

Energía

{productionMetrics.energyUsage} kW

Normal

Personal

{productionMetrics.staffUtilization}%

3/4 activos
{/* Tabs Navigation */}
{[ { id: 'schedule', label: 'Programa', icon: Calendar }, { id: 'batches', label: 'Lotes Activos', icon: Timer }, { id: 'analytics', label: 'Análisis', icon: BarChart3 }, { id: 'staff', label: 'Personal', icon: Users }, { id: 'equipment', label: 'Equipos', icon: Settings } ].map((tab) => ( ))}
{/* Tab Content */}
{activeTab === 'schedule' && ( <> { setProductionSchedule(prev => prev.map(slot => ({ ...slot, items: slot.items.map(item => item.id === itemId ? { ...item, quantity } : item ) })) ); }} onUpdateStatus={(itemId, status) => { setProductionSchedule(prev => prev.map(slot => ({ ...slot, items: slot.items.map(item => item.id === itemId ? { ...item, status } : item ) })) ); }} /> )} {activeTab === 'batches' && (
{productionBatches.map((batch) => (

{batch.product}

{batch.status === 'planned' ? 'Planificado' : batch.status === 'in_progress' ? 'En Progreso' : batch.status === 'completed' ? 'Completado' : 'Retrasado'}

Tamaño del Lote

{batch.batchSize} unidades

Rendimiento

{batch.actualYield || 0}/{batch.expectedYield}

Inicio

{batch.startTime}

Fin Estimado

{batch.endTime}

{(batch.temperature || batch.humidity) && (
{batch.temperature && (

Temperatura

{batch.temperature}°C

)} {batch.humidity && (

Humedad

{batch.humidity}%

)}
)}

Personal Asignado

{batch.assignedStaff.map((staffId) => { const staffMember = staff.find(s => s.id === staffId); return ( {staffMember?.name || staffId} ); })}
{batch.notes && (

{batch.notes}

)}
))}
)} {activeTab === 'analytics' && (
{ console.log('Selected date:', date); }} /> {/* Production Trends Chart Placeholder */}

Tendencias de Producción

Gráfico de tendencias de producción

Próximamente disponible

)} {activeTab === 'staff' && (
{staff.map((member) => (

{member.name}

{member.status === 'available' ? 'Disponible' : member.status === 'busy' ? 'Ocupado' : 'Descanso'}

Rol

{member.role}

{member.currentTask && (

Tarea Actual

{member.currentTask}

)}

Eficiencia

{member.efficiency}%
))}
)} {activeTab === 'equipment' && (
{equipment.map((item) => (

{item.name}

{item.status === 'idle' ? 'Inactivo' : item.status === 'in_use' ? 'En Uso' : item.status === 'maintenance' ? 'Mantenimiento' : 'Error'}

Tipo

{item.type}

{item.currentBatch && (

Lote Actual

{productionBatches.find(b => b.id === item.currentBatch)?.product || item.currentBatch}

)} {item.temperature && (

Temperatura

{item.temperature}°C

)} {item.maintenanceDue && (

Próximo Mantenimiento

{new Date(item.maintenanceDue).toLocaleDateString('es-ES')}

)}
))}
)}
); }; export default ProductionPage;