'use client'; import { useEffect, useState } from 'react'; import Link from 'next/link'; import { useCart } from '@/lib/cartStore'; import { getColorName } from '@/lib/colorNames'; import Price from '@/components/Price'; export default function CartPage() { const [mounted, setMounted] = useState(false); const items = useCart((s) => s.items); const removeItem = useCart((s) => s.removeItem); const setQuantity = useCart((s) => s.setQuantity); const total = useCart((s) => s.total()); const hasCustomDesign = items.some((item) => { try { const design = typeof item.designJson === 'string' ? JSON.parse(item.designJson) : item.designJson; return (design.front?.length ?? 0) > 0 || (design.back?.length ?? 0) > 0; } catch { return false; } }); useEffect(() => setMounted(true), []); const handleCheckout = () => { // Set flag so LogoutOnUnload doesn't clear cart during navigation to checkout if (typeof window !== 'undefined') { sessionStorage.setItem('isCheckingOut', 'true'); console.log('💳 Cart checkout button clicked - set isCheckingOut flag'); } window.location.href = '/checkout'; }; if (!mounted) return null; if (items.length === 0) { return (

Your bag

Nothing in here yet.

Start designing Shop ready-made
); } return (

Your bag

{items.map((item) => { const design = typeof item.designJson === 'string' ? JSON.parse(item.designJson) : item.designJson; const hasFront = (design.front?.length ?? 0) > 0; const hasBack = (design.back?.length ?? 0) > 0; return (
{item.placementPreviewUrl || item.designPreviewUrl ? ( {item.name} ) : (
No preview
)}

{item.name}

{getColorName(item.color)} {item.size && Size {item.size}}
{(hasFront || hasBack) && (

Custom design {hasFront && hasBack ? ' — front & back' : hasBack ? ' — back' : ' — front'}

{hasFront && item.designPreviewUrl && ( Download front PNG )} {hasBack && item.designPreviewUrlBack && ( Download back PNG )}
)}
{item.quantity}
{Number.isFinite(item.unitPrice) ? ( ) : ( — )}
); })}
{hasCustomDesign && (

Please check your design before checking out

We print exactly what's shown in your preview above — spelling, wording, and approximate placement included. Once your order's placed, that design goes straight to print, so take a moment to make sure everything looks right.

)}
Subtotal

You'll enter payment details on the next step.

By placing an order you agree to our{' '} Terms {' '} and{' '} Returns policy .

); }