'use client';
/**
* Wishlist link for the site header: a heart plus a count bubble, a client island so it
* can read the live saved-item count from useWishlist().
*
* It is a real LINK to /wishlist, like the cart beside it. The bubble is `aria-hidden`;
* the accessible name carries the count. The bubble only shows when the list has really
* loaded and is not empty: while it loads, or when it could not be loaded, there is NO
* number, because a failed load must never read as "0 saved".
*/
import * as React from 'react';
import { SmartLink } from '@/core/lib/navigation';
import { useWishlist } from '@/core/hooks/use-wishlist';
import { useTranslations } from '@/core/lib/translations';
import { IconHeart } from '@/ui/shared/icons';
/** The number to show: only when the list has really loaded, never for a failed load. */
function useShownCount(): number {
const { status, count } = useWishlist();
return status === 'ready' ? count : 0;
}
export function HeaderWishlist({ hideOnMobile = false }: { hideOnMobile?: boolean }) {
const shown = useShownCount();
const t = useTranslations('nav');
const label =
shown <= 0
? t('wishlist')
: shown === 1
? t('wishlistCountOne')
: t('wishlistCountOther', { count: String(shown) });
return (
{shown > 0 && (
{shown > 99 ? '99+' : shown}
)}
);
}
/**
* The same link as a row of the mobile menu (below `sm` the header icon is hidden so the burger
* stays on screen, see `hideOnMobile`). The count is part of the visible text.
*/
export function HeaderWishlistMenuItem({ className }: { className?: string }) {
const shown = useShownCount();
const t = useTranslations('nav');
return (
{t('wishlist')}
{shown > 0 ? ` (${shown})` : ''}
);
}