"use client"; import React from 'react'; import { Heart, X, ShoppingCart } from 'lucide-react'; import Link from 'next/link'; import { useCartStore } from '@/store/cartStore'; import { getImageUrl, formatCurrency } from '@/lib/utils'; interface WishlistModalProps { onClose: () => void; } export const WishlistModal: React.FC = ({ onClose }) => { // Read directly from Zustand store — no localStorage mismatch const wishlist = useCartStore((state) => state.wishlist); const toggleWishlist = useCartStore((state) => state.toggleWishlist); const addToCart = useCartStore((state) => state.addToCart); React.useEffect(() => { document.body.style.overflow = 'hidden'; const handleKeyDown = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose(); }; document.addEventListener('keydown', handleKeyDown); return () => { document.body.style.overflow = ''; document.removeEventListener('keydown', handleKeyDown); }; }, [onClose]); const handleMoveToCart = (product: any) => { const variant = product.variants?.[0]; if (variant) { addToCart(product, variant, 1); toggleWishlist(product); // remove from wishlist } }; const getPrice = (product: any): number => { return product.variants?.[0]?.price ?? 0; }; const getImage = (product: any): string => { const img = product.variants?.[0]?.images?.[0] ?? product.image ?? ''; return getImageUrl(img); }; return (
e.stopPropagation()} className="bg-white w-full max-w-[740px] rounded-2xl shadow-2xl overflow-hidden relative flex flex-col max-h-[85vh] text-left" > {/* Header */}

Wishlist ({wishlist.length})

{/* Wishlist Items */} {wishlist.length === 0 ? (

Your wishlist is empty!

Add items from the store to see them here.

) : (
{wishlist.map((product) => { const price = getPrice(product); const imgSrc = getImage(product); const slug = product.slug ?? product.product_id; return (
{/* Product Image */} {imgSrc ? ( {product.name} ) : (
No Image
)}
{/* Product Name */} {product.name} {/* Price */}

{formatCurrency(price)}

{/* SKU */}

SKU: {product.variants?.[0]?.sku ?? '—'}

{/* Actions */}
); })}
)}
); };