'use client'; import { useRouter, useSearchParams } from 'next/navigation'; import { useEffect, useState } from 'react'; import { Check, Link2, Search, X } from 'lucide-react'; interface Suggestion { type: string; label: string; sublabel: string | null; href: string; } const SLOTS = ['a', 'b', 'c', 'd'] as const; /** Four slot pickers with suggestions; values are asset slugs or index tickers, stored in the URL. */ export function CompareForm({ initial }: { initial: string[] }) { const router = useRouter(); const params = useSearchParams(); const [values, setValues] = useState([...initial, '', '', '', ''].slice(0, 4)); const [typing, setTyping] = useState<{ i: number; q: string } | null>(null); const [items, setItems] = useState([]); useEffect(() => { if (!typing || typing.q.trim().length < 2) return; const ctrl = new AbortController(); const t = setTimeout(() => { fetch(`/api/search/suggest?q=${encodeURIComponent(typing.q)}`, { signal: ctrl.signal }) .then((r) => r.json()) .then((d: { items: Suggestion[] }) => setItems((d.items ?? []).filter((x) => x.type === 'asset' || x.type === 'index').slice(0, 8))) .catch(() => {}); }, 150); return () => { clearTimeout(t); ctrl.abort(); }; }, [typing]); const apply = (vals: string[]) => { const sp = new URLSearchParams(); vals.forEach((v, i) => { if (v.trim()) sp.set(SLOTS[i]!, v.trim()); }); const w = params?.get('w'); if (w) sp.set('w', w); router.push(`/compare?${sp.toString()}`); }; return (
{ e.preventDefault(); apply(values); }} > {SLOTS.map((s, i) => ( ))}
Tickers: RARE, RARE-TCG, RARE-SPORT, RARE-WATCH, RARE-SNEAKER, RARE-LEGO, RARE-COMIC, RARE-GAME…
); } export function ShareButton() { const [done, setDone] = useState(false); return ( ); }