"use client"; import React from "react"; import Link from "next/link"; import Image from "next/image"; import { useContextElement } from "@/context/Context"; import DropdownSelect from "../common/DropdownSelect"; export default function ShopCart() { const { cartProducts, setCartProducts, totalPrice, updateQuantity, } = useContextElement(); const removeItem = (id) => { setCartProducts((pre) => [...pre.filter((elm) => elm.id != id)]); }; return (

Products

{cartProducts.length ? ( <> {cartProducts.map((product, i) => (
item
{product.title}
${product.price.toFixed(2)} {product.oldPrice && ( ${product.oldPrice.toFixed(2)} )}
updateQuantity( product.id, product.quantity - 1 ) } > - updateQuantity( product.id, product.quantity + 1 ) } > +
removeItem(product.id)} className="remove-cart" >
))} ) : (
Your Cart is empty. Start adding favorite products to cart!{" "}
Explore Products
)}

Cart totals

{cartProducts.map((product, i) => (
{product.title}
x{product.quantity}{" "}
${(product.price * product.quantity).toFixed(2)}
))}
Subtotal ${totalPrice.toFixed(2)}
Total ${totalPrice.toFixed(2)}
Check Out
); }