const CartDrawer = ({ cart, isOpen, onClose, setCart, setPage, lang }) => { const t = (en, id) => lang === "id" ? id : en; const updateQty = (key, delta) => { setCart(prev => prev.map(item => item.cartKey === key ? { ...item, qty: Math.max(1, item.qty + delta) } : item )); }; const remove = (key) => setCart(prev => prev.filter(item => item.cartKey !== key)); const total = cart.reduce((sum, item) => sum + item.price * item.qty, 0); const count = cart.reduce((sum, item) => sum + item.qty, 0); return (
{/* Header */}

{t("Your Cart", "Keranjang")}

{count} {t("item(s)", "produk")}

{/* Items */}
{cart.length === 0 ? (

{t("Your cart is empty", "Keranjang masih kosong")}

) : (
{cart.map(item => (
{item.name}

{item.name}

{(() => { // Gabung opsi jadi satu baris; buang warna kalau sama dgn varian (hindari dobel) const sameCV = item.selectedColor && item.selectedVariant && String(item.selectedColor).toLowerCase().trim() === String(item.selectedVariant).toLowerCase().trim(); const opts = [ item.selectedVariant, sameCV ? null : item.selectedColor, item.selectedSize, ].filter(Boolean); return opts.length > 0 ? (

{opts.join(" ยท ")}

) : null; })()}
{item.qty}
{formatPrice(item.price * item.qty)}
))}
)}
{/* Footer */} {cart.length > 0 && (
{t("Subtotal", "Subtotal")} {formatPrice(total)}
{t("Shipping", "Ongkir")} {t("FREE", "GRATIS")}
{t("Total", "Total")} {formatPrice(total)}
)}
); }; Object.assign(window, { CartDrawer });