// Map category IDs to one or more product cat tags const CAT_MAP = { gpu: ["GPU"], cpu: ["CPU"], mb: ["MOBO"], ram: ["RAM"], ssd: ["SSD"], psu: ["PSU"], case: ["CASE", "GAMING PC", "MINI PC", "STREAMER"], cool: ["COOLING"], mon: ["MONITOR"], kb: ["KEYBOARD"], ms: ["MOUSE"], head: ["AUDIO"], }; const ShopPage = () => { const params = new URLSearchParams(location.search); const catId = params.get("cat") || "gpu"; const meta = CATEGORIES.find(c => c.id === catId) || CATEGORIES[0]; const [sort, setSort] = React.useState("popular"); const [view, setView] = React.useState("grid"); const [priceMax, setPriceMax] = React.useState(400000); const [brandFilter, setBrandFilter] = React.useState(new Set()); const [stockOnly, setStockOnly] = React.useState(false); const [saleOnly, setSaleOnly] = React.useState(false); const allCatProducts = React.useMemo(() => { const tags = CAT_MAP[catId] || []; return [...PRODUCTS, ...PREBUILT].filter(p => tags.includes(p.cat)); }, [catId]); const brands = React.useMemo(() => [...new Set(allCatProducts.map(p => p.brand))], [allCatProducts]); const products = React.useMemo(() => { let list = allCatProducts.filter(p => p.price <= priceMax); if (brandFilter.size) list = list.filter(p => brandFilter.has(p.brand)); if (stockOnly) list = list.filter(p => p.stock > 0); if (saleOnly) list = list.filter(p => p.was); if (sort === "lowhigh") list.sort((a,b) => a.price - b.price); if (sort === "highlow") list.sort((a,b) => b.price - a.price); if (sort === "rating") list.sort((a,b) => b.rating - a.rating); if (sort === "new") list.sort((a,b) => b.id - a.id); return list; }, [allCatProducts, sort, priceMax, brandFilter, stockOnly, saleOnly]); const toggleBrand = (b) => setBrandFilter(prev => { const n = new Set(prev); n.has(b) ? n.delete(b) : n.add(b); return n; }); return ( {({ addToCart, openModal, faves, toggleFav }) => (
{/* Hero header */}
Home Shop {meta.label}

{meta.label}

{allCatProducts.length} products from {brands.length} brands · All compatibility-checked, 2-year warranty, free delivery on 50K+.

{CATEGORIES.slice(0,8).map(c => ( {c.label} ))}
{/* Listing */}
{/* Sidebar */} {/* Main listing */}
{products.length} result{products.length === 1 ? "" : "s"} {[...brandFilter].map(b => ( {b} ))} {stockOnly && ( In stock )} {saleOnly && ( On sale )}
{products.length === 0 ? (

No products match these filters

Try widening your price range or clearing brand filters.

) : view === "grid" ? (
{products.map(p => ( ))}
) : (
{products.map(p => )}
)} {products.length > 0 && (
)}
)}
); }; const ProductListRow = ({ p, onOpen, onAdd, faved, onFav }) => { const discount = p.was ? Math.round((1 - p.price / p.was) * 100) : 0; return (
{p.img && {p.name}}
{p.badges.map((b, i) => { const cls = b.includes("%") ? "sale" : b === "NEW" ? "new" : "hot"; return {b}; })}
{p.brand}

{p.name}

{p.rating.toFixed(1)} · {p.reviews} reviews · In stock
{p.specs.map((s, i) => {s})}
Free delivery 2y warranty 14d returns
{p.was && (
{money(p.was)} save {discount}%
)}
{money(p.price)} {p.currency}
VAT inc.
); }; ReactDOM.createRoot(document.getElementById("root")).render();