"use client"; import { useContextElement } from "@/context/Context"; import Image from "next/image"; import Link from "next/link"; export default function ShopCart() { const { cartProducts, setCartProducts, totalPrice } = useContextElement(); const setQuantity = (id, quantity) => { if (quantity >= 1) { const item = cartProducts.filter((elm) => elm.id == id)[0]; const items = [...cartProducts]; const itemIndex = items.indexOf(item); item.quantity = quantity; items[itemIndex] = item; setCartProducts(items); } }; const removeItem = (id) => { setCartProducts((pre) => [...pre.filter((elm) => elm.id != id)]); }; return (
{cartProducts.length ? (
{cartProducts.map((product, i) => ( ))}
Product
Price
Quantity
Total
{product.title}

{product.title}

Color: Black
Size: 43

{product.originalPrice ? ( <> ${product.originalPrice.toFixed(2)} {" "} ${product.price.toFixed(2)} ) : ( ${product.price.toFixed(2)} )}

{/*/.form-select-wrapper */}

${(product.price * product.quantity).toFixed(2)}

removeItem(product.id)} className="!text-[#343f52] hover:!text-[#1fc76f]" >
) : ( <>
Cart is empty
Explore Products )} {/* /.table-responsive */}
{/* /.input-group */}
{/* /column */} {/* /column */}
{/* /.row */}
{/* /column */}

Order Summary

Subtotal

${totalPrice.toFixed(2)}

Discount (5%)

-${totalPrice ? (totalPrice / 100) * 5 : 0}

Shipping

${totalPrice ? 10 : 0}

Grand Total

$ {totalPrice ? (totalPrice - (totalPrice / 100) * 5 + 10).toFixed( 2 ) : 0}

Proceed to Checkout
{/* /column */}
{/* /.row */}
{/* /.container */}
); }