/** * @component StoreHeader * @purpose Storefront header matching TechShop reference UI with logo, category search bar, blue search button, wishlist counter, account login, and shopping cart counter. * @dependencies cartStore, LiveSearch, lucide-react */ 'use client'; import { useState, useEffect } from 'react'; import Link from 'next/link'; import { ShoppingBag, Heart, User, ShoppingCart } from 'lucide-react'; import { useCartStore } from '@/store/cartStore'; import { LiveSearch } from './LiveSearch'; import { formatCurrency } from '@/lib/utils'; import { storefrontService, StorefrontSettings } from '@/services/api/storefrontService'; import { getMediaUrl } from '@/services/api/client'; export function StoreHeader() { const itemCount = useCartStore((state) => state.getItemCount()); const cartTotal = useCartStore((state) => state.getCartTotal()); const wishlistCount = useCartStore((state) => state.wishlist.length); const setCartDrawerOpen = useCartStore((state) => state.setCartDrawerOpen); const [settings, setSettings] = useState(null); useEffect(() => { storefrontService.getSettings().then((s) => { setSettings(s); if (s?.favicon_url && typeof window !== 'undefined') { let link = document.querySelector("link[rel*='icon']") as HTMLLinkElement; if (!link) { link = document.createElement('link'); link.rel = 'shortcut icon'; document.head.appendChild(link); } link.href = getMediaUrl(s.favicon_url); } }).catch(() => {}); }, []); const logoUrl = settings?.logo_url || settings?.primary_wordmark_url; const storeName = settings?.store_name || 'iFixKart'; const logoMediaUrl = getMediaUrl(logoUrl); return (
{/* Dynamic Store Logo */} {logoMediaUrl ? ( /* eslint-disable-next-line @next/next/no-img-element */ {storeName} { // If logo image fails to load, fall back to text (e.target as HTMLElement).style.display = 'none'; }} /> ) : ( iFixKart )} {/* Live Catalog Search Component */} {/* Action Counters */}
{/* Wishlist */}
{wishlistCount > 0 && ( {wishlistCount} )}
{/* Account */}
My Account Login
{/* Shopping Cart Drawer Trigger */}
); }