import { useState } from 'react'; export default function Cart({ isOpen, onClose, cartItems, onRemoveFromCart, onUpdateQuantity }) { const [isLoading, setIsLoading] = useState(false); const subtotal = cartItems.reduce((acc, item) => acc + item.price * item.quantity, 0); const shipping = subtotal > 35 ? 0 : 5.99; const total = subtotal + shipping; const handleCheckout = async () => { setIsLoading(true); // Simulate checkout await new Promise(resolve => setTimeout(resolve, 2000)); setIsLoading(false); alert('Thank you for your order! This is a demo.'); }; if (!isOpen) return null; return ( <> {/* Backdrop */}
{/* Cart Sidebar */}
{/* Cart Header */}

Shopping Cart

{/* Cart Items */}
{cartItems.length === 0 ? (

Your cart is empty

Looks like you haven't added anything yet

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

{item.name}

${item.price.toFixed(2)}

In Stock

{/* Quantity Controls */}
Qty:
))}
)}
{/* Cart Footer */} {cartItems.length > 0 && (
Subtotal ({cartItems.length} items): ${subtotal.toFixed(2)}
Shipping: {shipping === 0 ? 'FREE' : `$${shipping.toFixed(2)}`}
{subtotal < 35 && (

Add ${(35 - subtotal).toFixed(2)} more for FREE shipping

)}
Total: ${total.toFixed(2)}
)}
); }