import { useState, useEffect } from 'react'; interface RecentItem { id: string; slug: string; name: string; brand: string; price: number; image: string; } const STORAGE_KEY = 'sp_recently_viewed'; const MAX_ITEMS = 8; /** Call this on product pages to track viewed items */ export function trackView(item: RecentItem) { try { const stored = JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]') as RecentItem[]; const filtered = stored.filter(i => i.id !== item.id); filtered.unshift(item); localStorage.setItem(STORAGE_KEY, JSON.stringify(filtered.slice(0, MAX_ITEMS))); } catch {} } export default function RecentlyViewed() { const [items, setItems] = useState([]); useEffect(() => { try { const stored = JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]') as RecentItem[]; if (stored.length > 0) setItems(stored); } catch {} }, []); if (items.length === 0) return null; return (

Recent bekeken

{items.map(item => (
{`${item.brand} { (e.target as HTMLImageElement).src = '/img/sneaker-placeholder.svg'; }} />

{item.brand}

{item.name}

€{item.price.toFixed(2).replace('.', ',')}

))}
); }