'use client'; import { Suspense, useMemo, useState } from 'react'; import { useSearchParams, useRouter, usePathname } from 'next/navigation'; import { ROBOTS, CATEGORY_LABELS, BRANDS, type RobotCategory, type RobotBrand } from '@/data/robots'; import { RobotProductCard } from '@/components/robotics/RobotProductCard'; import { ProductFilterTabs, type Tab } from '@/components/robotics/ProductFilterTabs'; type Filter = { brand: RobotBrand | 'all'; category: RobotCategory | 'all' }; function CatalogInner() { const params = useSearchParams(); const router = useRouter(); const pathname = usePathname(); const initialBrand = (params.get('brand') as RobotBrand) || 'all'; const initialCategory = (params.get('category') as RobotCategory) || 'all'; const [filter, setFilter] = useState({ brand: initialBrand, category: initialCategory }); const filtered = useMemo(() => { return ROBOTS.filter((r) => { if (filter.brand !== 'all' && r.brand !== filter.brand) return false; if (filter.category !== 'all' && !r.categories.includes(filter.category)) return false; return true; }); }, [filter]); const updateFilter = (next: Partial) => { const newFilter = { ...filter, ...next }; setFilter(newFilter); const sp = new URLSearchParams(); if (newFilter.brand !== 'all') sp.set('brand', newFilter.brand); if (newFilter.category !== 'all') sp.set('category', newFilter.category); const qs = sp.toString(); router.replace(qs ? `${pathname}?${qs}` : pathname, { scroll: false }); }; const brandTabs: Tab[] = [ { id: 'all', label: 'All brands' }, ...(Object.keys(BRANDS) as RobotBrand[]).map((b) => ({ id: b, label: BRANDS[b].name.split(' ')[0], accent: BRANDS[b].accent, })), ]; const categoryTabs: Tab[] = [ { id: 'all', label: 'All' }, ...(Object.keys(CATEGORY_LABELS) as RobotCategory[]).map((c) => ({ id: c, label: CATEGORY_LABELS[c], })), ]; return (
updateFilter({ brand: id as RobotBrand | 'all' })} /> updateFilter({ category: id as RobotCategory | 'all' })} />
{filtered.length} robot{filtered.length === 1 ? '' : 's'} found {(filter.brand !== 'all' || filter.category !== 'all') && ( )}
{filtered.length === 0 ? (
No robots match these filters yet. Try a different brand or category, or{' '} contact us for tailored options.
) : (
{filtered.map((r) => ( ))}
)}
); } export function CatalogClient() { return ( Loading catalog…}> ); }