import { useState, useMemo } from 'react' import { Link } from 'react-router-dom' import { mockProducts } from '../lib/mock-data.ts' export function Products() { const [search, setSearch] = useState('') const filtered = useMemo(() => { if (!search.trim()) return mockProducts const q = search.toLowerCase() return mockProducts.filter( (p) => p.name.toLowerCase().includes(q) || p.brand.toLowerCase().includes(q) || p.category.toLowerCase().includes(q), ) }, [search]) const lowestPrice = (product: typeof mockProducts[0]) => Math.min(...product.prices.map((p) => p.price)) return (

Products

{/* Search input */}
setSearch(e.target.value)} className="min-h-12 w-full rounded-xl border border-gray-200 bg-white px-4 text-base shadow-sm focus:border-brand-blue focus:outline-none focus:ring-1 focus:ring-brand-blue" />
{/* Product list */}
{filtered.length === 0 ? (

No products match "{search}".

) : ( filtered.map((product) => { const low = lowestPrice(product) const cheapest = product.prices.find((p) => p.price === low) return (

{product.name}

{product.brand} · {product.category}

${low.toFixed(2)}

{cheapest?.storeName}

{product.prices.map((pp) => ( {pp.storeName} ${pp.price.toFixed(2)} ))}
) }) )}
) }