'use client';
/**
* Wishlist link for the site header (bare skeleton): a client island so it can read
* the live saved-item count from useWishlist().
*
* It is a real LINK to /wishlist. The accessible name carries the count, so the
* visible count is `aria-hidden`. The count 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';
/** 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 (
// `hideOnMobile`: below `sm` the link moves into the mobile menu (HeaderWishlistMenuItem) so
// the header's right cluster never pushes the menu button off a phone screen. Keep that.
{/* DESIGN ME — header wishlist link: heart icon + count badge; count via useWishlist().count (only when status === 'ready'), label via the `nav` translation namespace. Keep it a link to /wishlist with the aria-label above. Compose with the shadcn/ui primitives in src/components/ui (Button, Card, Badge, Input, Select, Accordion, Dialog, Skeleton, ...) + lucide-react icons. */}
{t('wishlist')}
{shown > 0 && (
{shown > 99 ? '99+' : shown}
)}
);
}
/**
* The same link as a row of the mobile menu (below `sm` the header link is hidden, 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})` : ''}
);
}