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...
Start adding products you love to your wishlist
{isLoggedIn ? `${items.length} items` : `${guestWishlistIds.length} items`}
Guest Wishlist: You have {guestWishlistIds.length} items saved locally. Login to see full details and sync your wishlist.
Login to see details
{item.price}
{item.stock_status === 'outofstock' && (Out of stock
)}