import React, { useState } from 'react'; import { Plus, Download, AlertTriangle, Package, Clock, CheckCircle, Eye, Edit, Calendar, DollarSign } from 'lucide-react'; import { Button, Input, Card, Badge, StatsGrid } from '../../../../components/ui'; import { formatters } from '../../../../components/ui/Stats/StatsPresets'; import { PageHeader } from '../../../../components/layout'; import { InventoryForm, LowStockAlert } from '../../../../components/domain/inventory'; const InventoryPage: React.FC = () => { const [searchTerm, setSearchTerm] = useState(''); const [showForm, setShowForm] = useState(false); const [selectedItem, setSelectedItem] = useState(null); const mockInventoryItems = [ { id: '1', name: 'Harina de Trigo', category: 'Harinas', currentStock: 45, minStock: 20, maxStock: 100, unit: 'kg', cost: 1.20, supplier: 'Molinos del Sur', lastRestocked: '2024-01-20', expirationDate: '2024-06-30', status: 'normal', }, { id: '2', name: 'Levadura Fresca', category: 'Levaduras', currentStock: 8, minStock: 10, maxStock: 25, unit: 'kg', cost: 8.50, supplier: 'Levaduras SA', lastRestocked: '2024-01-25', expirationDate: '2024-02-15', status: 'low', }, { id: '3', name: 'Mantequilla', category: 'Lácteos', currentStock: 15, minStock: 5, maxStock: 30, unit: 'kg', cost: 5.80, supplier: 'Lácteos Frescos', lastRestocked: '2024-01-24', expirationDate: '2024-02-10', status: 'normal', }, { id: '4', name: 'Azúcar Blanco', category: 'Azúcares', currentStock: 0, minStock: 15, maxStock: 50, unit: 'kg', cost: 0.95, supplier: 'Distribuidora Central', lastRestocked: '2024-01-10', expirationDate: '2024-12-31', status: 'out', }, { id: '5', name: 'Leche Entera', category: 'Lácteos', currentStock: 3, minStock: 10, maxStock: 40, unit: 'L', cost: 1.45, supplier: 'Lácteos Frescos', lastRestocked: '2024-01-22', expirationDate: '2024-01-28', status: 'expired', }, ]; const getStockStatusBadge = (item: typeof mockInventoryItems[0]) => { const { currentStock, minStock, status } = item; if (status === 'expired') { return ( } text="Caducado" /> ); } if (currentStock === 0) { return ( } text="Sin Stock" /> ); } if (currentStock <= minStock) { return ( } text="Stock Bajo" /> ); } return ( } text="Normal" /> ); }; const getCategoryBadge = (category: string) => { const categoryConfig = { 'Harinas': { color: 'default' }, 'Levaduras': { color: 'info' }, 'Lácteos': { color: 'secondary' }, 'Grasas': { color: 'warning' }, 'Azúcares': { color: 'primary' }, 'Especias': { color: 'success' }, }; const config = categoryConfig[category as keyof typeof categoryConfig] || { color: 'default' }; return ( ); }; const filteredItems = mockInventoryItems.filter(item => { const matchesSearch = item.name.toLowerCase().includes(searchTerm.toLowerCase()) || item.category.toLowerCase().includes(searchTerm.toLowerCase()) || item.supplier.toLowerCase().includes(searchTerm.toLowerCase()); return matchesSearch; }); const lowStockItems = mockInventoryItems.filter(item => item.currentStock <= item.minStock || item.status === 'low' || item.status === 'out' || item.status === 'expired' ); const mockInventoryStats = { totalItems: mockInventoryItems.length, lowStockItems: lowStockItems.length, outOfStock: mockInventoryItems.filter(item => item.currentStock === 0).length, expiringSoon: mockInventoryItems.filter(item => item.status === 'expired').length, totalValue: mockInventoryItems.reduce((sum, item) => sum + (item.currentStock * item.cost), 0), categories: [...new Set(mockInventoryItems.map(item => item.category))].length, }; const inventoryStats = [ { title: 'Total Artículos', value: mockInventoryStats.totalItems, variant: 'default' as const, icon: Package, }, { title: 'Stock Bajo', value: mockInventoryStats.lowStockItems, variant: 'warning' as const, icon: AlertTriangle, }, { title: 'Sin Stock', value: mockInventoryStats.outOfStock, variant: 'error' as const, icon: AlertTriangle, }, { title: 'Por Caducar', value: mockInventoryStats.expiringSoon, variant: 'error' as const, icon: Clock, }, { title: 'Valor Total', value: formatters.currency(mockInventoryStats.totalValue), variant: 'success' as const, icon: DollarSign, }, { title: 'Categorías', value: mockInventoryStats.categories, variant: 'info' as const, icon: Package, }, ]; return (
console.log('Export inventory') }, { id: "new", label: "Nuevo Artículo", variant: "primary" as const, icon: Plus, onClick: () => setShowForm(true) } ]} /> {/* Stats Grid */} {/* Low Stock Alert */} {lowStockItems.length > 0 && ( )} {/* Simplified Controls */}
setSearchTerm(e.target.value)} className="w-full" />
{/* Inventory Items Grid */}
{filteredItems.map((item) => (
{/* Header */}
{item.name}
{item.supplier}
{getStockStatusBadge(item)}
{/* Category and Stock */}
{getCategoryBadge(item.category)}
{item.currentStock} {item.unit}
Mín: {item.minStock} | Máx: {item.maxStock}
{/* Value and Dates */}
Costo unitario:
{formatters.currency(item.cost)}
Valor total:
{formatters.currency(item.currentStock * item.cost)}
{/* Dates */}
Último restock: {new Date(item.lastRestocked).toLocaleDateString('es-ES')}
Caducidad: {new Date(item.expirationDate).toLocaleDateString('es-ES')}
{/* Stock Level Progress */}
Nivel de stock {Math.round((item.currentStock / item.maxStock) * 100)}%
{/* Actions */}
))}
{/* Empty State */} {filteredItems.length === 0 && (

No se encontraron artículos

Intenta ajustar la búsqueda o agregar un nuevo artículo al inventario

)} {/* Inventory Form Modal */} {showForm && ( { setShowForm(false); setSelectedItem(null); }} onSave={(item) => { // Handle save logic console.log('Saving item:', item); setShowForm(false); setSelectedItem(null); }} /> )}
); }; export default InventoryPage;