"use client"; import Image from "next/image"; import Link from "next/link"; import { Minus, Plus, ShoppingBag, Trash2 } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Progress } from "@/components/ui/progress"; import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle } from "@/components/ui/sheet"; import { formatMoney } from "@/lib/utils"; import { useCartStore } from "@/store/cart-store"; const FREE_SHIPPING_THRESHOLD = 250_000; export function CartDrawer() { const { items, isOpen, closeCart, updateQuantity, removeItem, clearCart } = useCartStore(); const subtotal = items.reduce((sum, item) => sum + (item.product.price ?? 0) * item.quantity, 0); const pricedItems = items.some((item) => item.product.price !== null); const progress = pricedItems ? Math.min(100, (subtotal / FREE_SHIPPING_THRESHOLD) * 100) : 0; const count = items.reduce((sum, item) => sum + item.quantity, 0); return ( { if (!open) closeCart(); }}> Tu carrito {count} producto{count === 1 ? "" : "s"} seleccionado{count === 1 ? "" : "s"}.
{items.length === 0 ? (

Tu carrito está vacío

Agrega un tesoro para comenzar.

) : items.map((item) => (
{item.product.name}

{item.product.name}

{formatMoney(item.product.price, item.product.currency)}

{item.quantity}
))}
{pricedItems ? "Progreso para envío gratis" : "Cotización personalizada"}{pricedItems ? `${Math.round(progress)}%` : "Por confirmar"}
Subtotal{pricedItems ? formatMoney(subtotal) : "Por confirmar"}
{/* Button asChild + disabled no funciona sobre un (:disabled es pseudo-clase de elementos de formulario, un Link nunca la cumple) -- se ramifica en vez de confiar en el prop disabled sobre un Link. */} {items.length > 0 ? ( ) : ( )}
); }