import React, { useState } from 'react'; import { Plus, Minus, ShoppingCart, CreditCard, Banknote, Calculator, User, Receipt } from 'lucide-react'; import { Button, Input, Card, Badge } from '../../../../components/ui'; import { PageHeader } from '../../../../components/layout'; const POSPage: React.FC = () => { const [cart, setCart] = useState>([]); const [selectedCategory, setSelectedCategory] = useState('all'); const [customerInfo, setCustomerInfo] = useState({ name: '', email: '', phone: '', }); const [paymentMethod, setPaymentMethod] = useState<'cash' | 'card' | 'transfer'>('cash'); const [cashReceived, setCashReceived] = useState(''); const products = [ { id: '1', name: 'Pan de Molde Integral', price: 4.50, category: 'bread', stock: 25, image: '/api/placeholder/100/100', }, { id: '2', name: 'Croissants de Mantequilla', price: 1.50, category: 'pastry', stock: 32, image: '/api/placeholder/100/100', }, { id: '3', name: 'Baguette Francesa', price: 2.80, category: 'bread', stock: 18, image: '/api/placeholder/100/100', }, { id: '4', name: 'Tarta de Chocolate', price: 25.00, category: 'cake', stock: 8, image: '/api/placeholder/100/100', }, { id: '5', name: 'Magdalenas', price: 0.75, category: 'pastry', stock: 48, image: '/api/placeholder/100/100', }, { id: '6', name: 'Empanadas', price: 2.50, category: 'other', stock: 24, image: '/api/placeholder/100/100', }, ]; const categories = [ { id: 'all', name: 'Todos' }, { id: 'bread', name: 'Panes' }, { id: 'pastry', name: 'Bollería' }, { id: 'cake', name: 'Tartas' }, { id: 'other', name: 'Otros' }, ]; const filteredProducts = products.filter(product => selectedCategory === 'all' || product.category === selectedCategory ); const addToCart = (product: typeof products[0]) => { setCart(prevCart => { const existingItem = prevCart.find(item => item.id === product.id); if (existingItem) { return prevCart.map(item => item.id === product.id ? { ...item, quantity: item.quantity + 1 } : item ); } else { return [...prevCart, { id: product.id, name: product.name, price: product.price, quantity: 1, category: product.category, }]; } }); }; const updateQuantity = (id: string, quantity: number) => { if (quantity <= 0) { setCart(prevCart => prevCart.filter(item => item.id !== id)); } else { setCart(prevCart => prevCart.map(item => item.id === id ? { ...item, quantity } : item ) ); } }; const clearCart = () => { setCart([]); }; const subtotal = cart.reduce((sum, item) => sum + (item.price * item.quantity), 0); const taxRate = 0.21; // 21% IVA const tax = subtotal * taxRate; const total = subtotal + tax; const change = cashReceived ? Math.max(0, parseFloat(cashReceived) - total) : 0; const processPayment = () => { if (cart.length === 0) return; // Process payment logic here console.log('Processing payment:', { cart, customerInfo, paymentMethod, total, cashReceived: paymentMethod === 'cash' ? parseFloat(cashReceived) : undefined, change: paymentMethod === 'cash' ? change : undefined, }); // Clear cart after successful payment setCart([]); setCustomerInfo({ name: '', email: '', phone: '' }); setCashReceived(''); alert('Venta procesada exitosamente'); }; return (
{/* Products Section */}
{/* Categories */}
{categories.map(category => ( ))}
{/* Products Grid */}
{filteredProducts.map(product => ( addToCart(product)} > {product.name}

{product.name}

€{product.price.toFixed(2)}

Stock: {product.stock}

))}
{/* Cart and Checkout Section */}
{/* Cart */}

Carrito ({cart.length})

{cart.length > 0 && ( )}
{cart.length === 0 ? (

Carrito vacío

) : ( cart.map(item => (

{item.name}

€{item.price.toFixed(2)} c/u

{item.quantity}

€{(item.price * item.quantity).toFixed(2)}

)) )}
{cart.length > 0 && (
Subtotal: €{subtotal.toFixed(2)}
IVA (21%): €{tax.toFixed(2)}
Total: €{total.toFixed(2)}
)}
{/* Customer Info */}

Cliente (Opcional)

setCustomerInfo(prev => ({ ...prev, name: e.target.value }))} /> setCustomerInfo(prev => ({ ...prev, email: e.target.value }))} /> setCustomerInfo(prev => ({ ...prev, phone: e.target.value }))} />
{/* Payment */}

Método de Pago

{paymentMethod === 'cash' && (
setCashReceived(e.target.value)} /> {cashReceived && parseFloat(cashReceived) >= total && (

Cambio: €{change.toFixed(2)}

)}
)}
); }; export default POSPage;