'use client'; /** * Wishlist link for the site header: a heart plus a live count of saved items. * * The header itself is a server component fed by merchant-configured Content, so the * count has to come from a small client island. It is a real LINK to /wishlist, like * the cart link beside it. The badge is `aria-hidden`; the accessible name carries the * count. * * The badge only shows when the list has really loaded and is not empty. While it is * loading, or when it could not be loaded, there is NO number: a failed load must never * read as "0 saved". */ import * as React from 'react'; import { Heart } from 'lucide-react'; import { SmartLink } from '@/core/lib/navigation'; import { useWishlist } from '@/core/hooks/use-wishlist'; import { useTranslations } from '@/core/lib/translations'; /** 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 ( ); } /** * The same link as a row of the mobile menu (below `sm` the header icon is hidden to keep the * burger on screen, see `hideOnMobile`). The count is part of the visible text, so a * screen reader reads it without an extra label. */ export function HeaderWishlistMenuItem({ className }: { className?: string }) { const shown = useShownCount(); const t = useTranslations('nav'); return ( {t('wishlist')} {shown > 0 ? ` (${shown})` : ''} ); }