import { useQuery, useQueryClient } from '@tanstack/react-query' import { Link, useNavigate } from 'react-router-dom' import { Trash2, Flower2, ShoppingCart } from 'lucide-react' import { getCart, updateCartItem, removeCartItem } from '../api/client' import { money, useShop } from '../store/shop' export default function Cart() { const qc = useQueryClient() const nav = useNavigate() const { custToken, setCartCount } = useShop() const { data: items } = useQuery({ queryKey: ['cart'], queryFn: getCart, enabled: !!custToken }) const refresh = () => qc.invalidateQueries({ queryKey: ['cart'] }) const setQty = async (id: number, q: number) => { if (q < 1) return; await updateCartItem(id, q); refresh() } const remove = async (id: number) => { await removeCartItem(id); refresh(); setCartCount((c: number) => Math.max(0, c - 1)) } if (!custToken) return (

Please sign in to view your cart.

Sign In / Register
) const list = items || [] const subtotal = list.reduce((s: number, i: any) => s + (i.price || (i.unitPrice || 0) * (i.quantity || 1)), 0) return (

Cart

{!list.length ? (
Your cart is empty. Start Shopping →
) : (
{list.map((i: any) => (
{i.thumbnail ? : }
{i.productName || `Product #${i.productId}`}
{i.sizeCode}{i.cardMessage ? ` · Card: ${i.cardMessage.slice(0, 20)}` : ''}
{i.quantity || 1}
{money(i.price || (i.unitPrice || 0) * (i.quantity || 1))}
))}
Subtotal{money(subtotal)}
Shipping/TaxCalculated at checkout
Total{money(subtotal)}
)}
) }