import React from 'react'; import { useNavigate } from 'react-router-dom'; import { Trash2, ShoppingCart, Heart } from 'lucide-react'; import { useWishlist } from '@/hooks/useWishlist'; import { useCartStore } from '@/lib/cart/store'; import { Button } from '@/components/ui/button'; import { toast } from 'sonner'; /** * Public Wishlist Page - Accessible to both guests and logged-in users * Guests: Shows items from localStorage * Logged-in: Shows items from database via API */ export default function Wishlist() { const navigate = useNavigate(); const { items, isLoading, isLoggedIn, removeFromWishlist, productIds } = useWishlist(); const { addItem } = useCartStore(); const handleRemove = async (productId: number) => { await removeFromWishlist(productId); }; const handleAddToCart = (productId: number, productName: string) => { // For guests with localStorage wishlist, we only have IDs // Navigate to product page for now navigate(`/product/${productId}`); }; if (isLoading) { return (

Loading wishlist...

); } // Guest mode: only have product IDs from localStorage const guestWishlistIds = !isLoggedIn ? Array.from(productIds) : []; const hasGuestItems = guestWishlistIds.length > 0; const hasLoggedInItems = items.length > 0; if (!hasGuestItems && !hasLoggedInItems) { return (

My Wishlist

Your wishlist is empty

Start adding products you love to your wishlist

); } return (

My Wishlist

{isLoggedIn ? `${items.length} items` : `${guestWishlistIds.length} items`}

{/* Guest Mode: Show IDs only with limited functionality */} {!isLoggedIn && hasGuestItems && (

Guest Wishlist: You have {guestWishlistIds.length} items saved locally. Login to see full details and sync your wishlist.

)} {/* Guest Wishlist Items (localStorage only - show IDs) */} {!isLoggedIn && hasGuestItems && (
{guestWishlistIds.map((productId: number) => (

Product #{productId}

Login to see details

))}
)} {/* Logged-in Wishlist Items (full details from API) */} {isLoggedIn && hasLoggedInItems && (
{items.map((item) => (
{item.image ? ( {item.name} ) : (
)}

{item.name}

{item.price}

{item.stock_status === 'outofstock' && (

Out of stock

)}
))}
)}
); }