diff --git a/src/pages/Cart.tsx b/src/pages/Cart.tsx new file mode 100644 index 0000000..9dd2f42 --- /dev/null +++ b/src/pages/Cart.tsx @@ -0,0 +1,177 @@ +import { useState } from "react"; +import { toast } from "sonner"; +import { Link } from "react-router-dom"; +import { Button } from "@/components/ui/button"; +import { Card, CardContent } from "@/components/ui/card"; +import { Badge } from "@/components/ui/badge"; +import { Input } from "@/components/ui/input"; +import { Separator } from "@/components/ui/separator"; +import { Minus, Plus, X, ShoppingBag, ArrowRight, ArrowLeft, Tag } from "lucide-react"; +import Header from "@/components/Header"; +import Footer from "@/components/Footer"; +import { useCart } from "@/lib/cart-context"; + +export default function CartPage() { + const { items, removeItem, updateQuantity, total, itemCount, clearCart } = useCart(); + const [coupon, setCoupon] = useState(""); + const [couponApplied, setCouponApplied] = useState(false); + + const shipping = total >= 100 ? 0 : 12.99; + const tax = total * 0.08; + const discount = couponApplied ? total * 0.1 : 0; + const grandTotal = total + shipping + tax - discount; + + const applyCoupon = () => { + if (coupon.trim().length > 0) { + setCouponApplied(true); + toast.success("Coupon applied!"); + } + }; + + if (items.length === 0) { + return ( +
+
+
+
+ +
+

Your cart is empty

+

Looks like you haven't added anything to your cart yet.

+ +
+
+ ); + } + + return ( +
+
+ +
+

Shopping Cart

+

{itemCount} {itemCount === 1 ? "item" : "items"} in your cart

+ +
+ {/* Cart Items */} +
+ {items.map((item) => ( + + +
+
+
+
+ Image +
+
+
+
+

{item.name}

+
+ {item.color && {item.color}} + {item.size && Size: {item.size}} +
+
+ +
+
+
+ + {item.quantity} + +
+ \${(item.price * item.quantity).toFixed(2)} +
+
+
+ + + ))} +
+ + {/* Order Summary */} +
+ + +

Order Summary

+ +
+
+ Subtotal + \${total.toFixed(2)} +
+
+ Shipping + + {shipping === 0 ? "Free" : `\$\${shipping.toFixed(2)}`} + +
+
+ Tax + \${tax.toFixed(2)} +
+ {couponApplied && ( +
+ Discount (10%) + -\${discount.toFixed(2)} +
+ )} +
+ + + +
+ Total + \${grandTotal.toFixed(2)} +
+ + {/* Coupon */} +
+
+ + setCoupon(e.target.value)} + className="pl-9 rounded-full text-sm" + /> +
+ +
+ + {shipping > 0 && ( +

+ Add \${(100 - total).toFixed(2)} more for free shipping +

+ )} + +
+ + +
+
+
+
+
+
+ +
+ ); +}