'use client' import { useState, useEffect, useCallback } from 'react' import { useRouter } from 'next/navigation' import { Button } from '@/components/ui/button' import { Card } from '@/components/ui/card' import { Separator } from '@/components/ui/separator' import { ArrowLeft, ShoppingCart, Trash2, Plus, Minus, Heart } from 'lucide-react' import { cartManager } from '@/lib/cart' import { toast } from 'sonner' import Link from 'next/link' import Image from 'next/image' import { motion } from 'framer-motion' import PageHero from '@/components/sections/PageHero' interface CartItem { id: string name: string price: number quantity: number image: string | null } export default function CartPage() { const router = useRouter() const [cart, setCart] = useState([]) const [updating, setUpdating] = useState(null) const loadCart = useCallback(() => { const cartItems = cartManager.getCart() setCart(cartItems || []) }, []) useEffect(() => { loadCart() const handleCartUpdate = () => loadCart() window.addEventListener('cartUpdated', handleCartUpdate) return () => { window.removeEventListener('cartUpdated', handleCartUpdate) } }, [loadCart]) const updateQuantity = async (productId: string, newQuantity: number) => { setUpdating(productId) cartManager.updateQuantity(productId, newQuantity) loadCart() setUpdating(null) } const removeItem = (productId: string) => { cartManager.removeFromCart(productId) toast.success('Item removed from cart') loadCart() } const getTotalPrice = () => { return cartManager.getTotalPrice() } const getTotalItems = () => { return cart.reduce((sum, item) => sum + item.quantity, 0) } if (cart.length === 0) { return (

Shopping Cart

Your cart is currently empty

Your cart is empty

Looks like you haven't added anything to your cart yet. Start shopping to fill it up!

) } return (
{/* Header */}

Shopping Cart

{getTotalItems()} {getTotalItems() === 1 ? 'item' : 'items'} in your cart

{/* Cart Items */}
{cart.map((item, index) => (
{/* Product Image */}
{item.name}
{/* Product Details */}

{item.name}

₹{(item.price || 0).toFixed(2)}

{/* Quantity Controls */}
{updating === item.id ? '...' : item.quantity}

₹{((item.price || 0) * item.quantity).toFixed(2)}

₹{(item.price || 0).toFixed(2)} each

))}
{/* Order Summary */}

Order Summary

Subtotal ({getTotalItems()} items) ₹{getTotalPrice().toFixed(2)}
Shipping Free
Tax Calculated at checkout
Total ₹{getTotalPrice().toFixed(2)}
{/* Security Badge */}
Secure checkout powered by Razorpay
) }