"use client" import { Suspense, useEffect, useState } from "react" import { useRouter, useSearchParams } from "next/navigation" import { ExternalLinkIcon, Gamepad2Icon, MessageSquareIcon, SettingsIcon, TrendingUpIcon } from "lucide-react" import Image from "next/image" interface UnifiedResult { kind: "local" | "steam" id?: string appId: number | null title: string image: string | null developer: string | null publisher: string | null source: string counts: { benchmarks: number; presets: number; comments: number } | null } function SearchContent() { const searchParams = useSearchParams() const router = useRouter() const query = searchParams.get("q") || "" const [results, setResults] = useState([]) const [loading, setLoading] = useState(false) const [error, setError] = useState(null) useEffect(() => { if (!query) { setResults([]) return } let cancelled = false async function fetchResults() { setLoading(true) setError(null) try { const res = await fetch( `/api/search/unified?q=${encodeURIComponent(query)}`, ) if (!res.ok) throw new Error(await res.text()) const data = await res.json() if (!cancelled) setResults(data.results || []) } catch (err) { if (!cancelled) { setError("Failed to fetch search results") console.error(err) } } finally { if (!cancelled) setLoading(false) } } fetchResults() return () => { cancelled = true } }, [query]) function handleClick(result: UnifiedResult) { const path = result.appId ? `/game/${result.appId}` : `/game/${result.id}` router.push(path) } return (

{query ? `results for "${query}"` : "search using game name or appid"}

{query ? `${results.length} result${results.length !== 1 ? "s" : ""} found` : "Enter a game name or AppID to find benchmarks, settings, and reviews."}

{!query && (

Start typing to search for games

)} {query && loading && (

Searching for "{query}"...

)} {query && !loading && error && (

{error}

)} {query && !loading && !error && results.length === 0 && (

No results found for "{query}"

)} {query && !loading && !error && results.length > 0 && (
{results.map((result, idx) => ( ))}
)}
) } function SearchResultCard({ result, onClick, }: { result: UnifiedResult onClick: (r: UnifiedResult) => void }) { const isLocal = result.kind === "local" const hasData = isLocal && result.counts && ( result.counts.benchmarks > 0 || result.counts.presets > 0 || result.counts.comments > 0 ) const hasDeveloperInfo = result.developer || result.publisher return (
onClick(result)} > {/* Image */}
{result.image ? ( {result.title} ) : (
)} {/* Source badge */}
{isLocal && ( In Database )} {!isLocal && result.appId && ( e.stopPropagation()} > Steam )}
{/* Info */}

{result.title}

{hasDeveloperInfo ? (

{result.developer || result.publisher}

) : !isLocal && result.appId ? (

AppID: {result.appId}

) : null}
{/* Stats (local only) */} {isLocal && result.counts && (
{result.counts.benchmarks > 0 && ( {result.counts.benchmarks} )} {result.counts.presets > 0 && ( {result.counts.presets} )} {result.counts.comments > 0 && ( {result.counts.comments} )} {!hasData && ( No data yet )}
)}
) } export default function SearchPage() { return ( ) }