/** * @component ProductGrid * @purpose Product Showcase grid with dynamic tab switching (All Products, Featured, On Sale, Best Sellers). * @a11y Accessible tab list, focus indicators * @dependencies ProductCard, catalogService */ 'use client'; import { useState, useEffect } from 'react'; import { catalogService, ProductResponse } from '@/services/api/catalogService'; import { ProductCard } from './ProductCard'; type FilterTab = 'all' | 'featured' | 'sale' | 'bestsellers'; export function ProductGrid() { const [products, setProducts] = useState([]); const [activeTab, setActiveTab] = useState('all'); useEffect(() => { catalogService.getProducts().then(setProducts); }, []); const filteredProducts = products .filter((p) => { if (activeTab === 'featured') return p.badge === 'HOT' || p.badge === 'NEW'; if (activeTab === 'sale') return p.badge === 'SALE' || p.variants[0]?.compare_price; if (activeTab === 'bestsellers') return (p.rating || 5) >= 4.8; return true; }) .slice(0, 8); // Limit to 8 items in the grid for supreme performance! return (
{/* Header & Dynamic Filter Tabs */}
Our Catalog

Featured Products

{/* Dynamic Filter Tabs */}
{( [ { id: 'all', label: 'All Products' }, { id: 'featured', label: 'Featured' }, { id: 'sale', label: 'On Sale' }, { id: 'bestsellers', label: 'Best Sellers' }, ] as const ).map((tab) => ( ))}
{/* Grid */}
{filteredProducts.map((product) => ( ))}
); }