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 (
Looks like you haven't added anything to your cart yet.
{itemCount} {itemCount === 1 ? "item" : "items"} in your cart
Add \${(100 - total).toFixed(2)} more for free shipping
)}