// Cart count badge in the site header. Lived inside `initTabs()` until the // dashboard strips became described regions and `core/tabs.ts` went away; it // was never tab behaviour, it just ran on every page from the one place that // already did. /** Fill the header cart link with its item count, and reveal it when non-zero. * Inert on pages without `#nav-cart-link` (`partials/site_header.html`). */ export function initCartBadge(): void { const cartLink = document.getElementById('nav-cart-link'); if (!cartLink) return; fetch('/api/cart/count', { credentials: 'same-origin' }) .then((r) => (r.ok ? r.json() : null)) .then((data: { count?: number } | null) => { if (data && typeof data.count === 'number' && data.count > 0) { cartLink.classList.remove('hidden'); const badge = document.getElementById('cart-badge'); if (badge) badge.textContent = ' (' + data.count + ')'; } }) .catch(() => {}); }