import { useParams, Link } from 'react-router-dom' import { useProduct } from '../hooks/useApi.ts' import { StoreIcon } from '../components/StoreIcon.tsx' export function StoreComparison() { const { productId } = useParams<{ productId: string }>() const { data: product, isLoading } = useProduct(productId ?? '') if (isLoading) { return (
{[1, 2, 3].map((i) => (
))}
) } if (!product) { return (

Product not found.

Back to products
) } const sorted = product.prices.slice().sort((a, b) => a.price - b.price) const lowestPrice = sorted[0]?.price ?? 0 const savings = sorted.length > 1 ? sorted[sorted.length - 1].price - sorted[0].price : 0 return (
{/* Back link */} {product.name}

Store Comparison

{product.name} · {product.brand}

{/* Savings banner */} {savings > 0 && (

Save ${savings.toFixed(2)} by shopping at {sorted[0].storeName}

)} {/* Store comparison cards */}
{sorted.map((pp, idx) => (

{pp.storeName}

Updated{' '} {new Date(pp.lastUpdated).toLocaleDateString('en-US', { month: 'short', day: 'numeric', })}

${pp.price.toFixed(2)}

{pp.price === lowestPrice ? ( Best price ) : ( +${(pp.price - lowestPrice).toFixed(2)} )}
))}

Prices last verified from store loyalty card data. Map view coming soon.

) }