import React, { useContext, useState } from 'react' import { Link, useNavigate } from 'react-router-dom' import { CartContext } from '../context/CartContext' import { AuthContext } from '../context/AuthContext' import Toast from '../components/Toast' import '../styles/global.css' export default function Cart() { const { cart, removeFromCart, updateQuantity, total, clearCart } = useContext(CartContext) const { token } = useContext(AuthContext) const navigate = useNavigate() const [toast, setToast] = useState(null) const handleCheckout = () => { if (!token) { navigate('/login') } else if (cart.length === 0) { setToast({ type: 'info', message: 'Your cart is empty' }) } else { navigate('/checkout') } } return (

Shopping Cart

{cart.length === 0 ? (

Your cart is empty

Continue Shopping
) : (
{cart.map((item, index) => ( ))}
Product Price Quantity Total Action
{item.product.name}

{item.product.name}

{item.size &&

Size: {item.size}

}
₪{(item.product.discount_price || item.product.price).toFixed(2)}
{item.quantity}
₪{((item.product.discount_price || item.product.price) * item.quantity).toFixed(2)}

Order Summary

Subtotal: ₪{total.toFixed(2)}
Shipping: $10.00
Tax: ₪{(total * 0.1).toFixed(2)}
Total: ₪{(total + 10 + total * 0.1).toFixed(2)}
)} {toast && ( setToast(null)} /> )}
) }