"use client"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardFooter, CardHeader, CardTitle } from "@/components/ui/card"; import { formatCurrency } from "@/lib/utils"; export interface CartItem { id: string; name: string; price: number; quantity: number; stock: number; trackStock: boolean; } interface CartProps { items: CartItem[]; onUpdateQuantity: (productId: string, quantity: number) => void; onRemoveItem: (productId: string) => void; onClearCart: () => void; onCheckout: () => void; disabled?: boolean; } export function Cart({ items, onUpdateQuantity, onRemoveItem, onClearCart, onCheckout, disabled = false, }: CartProps) { const subtotal = items.reduce( (sum, item) => sum + item.price * item.quantity, 0 ); const handleIncrement = (item: CartItem) => { // Check stock if tracking if (item.trackStock && item.quantity >= item.stock) { return; } onUpdateQuantity(item.id, item.quantity + 1); }; const handleDecrement = (item: CartItem) => { if (item.quantity > 1) { onUpdateQuantity(item.id, item.quantity - 1); } else { onRemoveItem(item.id); } }; return (
Carrito {items.length > 0 && ( )}
{items.length === 0 ? (
🛒

El carrito esta vacio

Selecciona productos para agregar

) : ( )}
{/* Total */}
Total: {formatCurrency(subtotal)}
{/* Checkout Button */}
); }