"use client" import { useState, useCallback } from "react" import { motion } from "motion/react" import { BarChart3Icon } from "lucide-react" import { GameSelector } from "@/components/compare/game-selector" import { StatsComparison } from "@/components/compare/stats-comparison" import { FpsComparisonChart } from "@/components/compare/fps-comparison-chart" import { StabilityRadar } from "@/components/compare/stability-radar" interface SelectedGame { id: string appId: number | null title: string image: string | null source: string } interface GameComparisonData { id: string title: string stats: { totalEntries: number avgFps: number | null medianFps: number | null bestFps: number | null avgOnePercentLow: number | null avgStability: number | null bestDevice: string | null tierBreakdown: { unplayable: number; playable: number; smooth: number; excellent: number } | null deviceBreakdown: Array<{ hardwareSlug: string; count: number; avgFps: number }> } } export default function ComparePage() { const [selectedGames, setSelectedGames] = useState([]) const [comparisonData, setComparisonData] = useState([]) const [loading, setLoading] = useState(false) const [error, setError] = useState(null) const handleSelect = useCallback((game: SelectedGame) => { setSelectedGames(prev => { if (prev.some(g => g.id === game.id)) return prev return [...prev, game] }) }, []) const handleRemove = useCallback((gameId: string) => { setSelectedGames(prev => prev.filter(g => g.id !== gameId)) setComparisonData(prev => prev.filter(g => g.id !== gameId)) }, []) const fetchComparison = useCallback(async () => { if (selectedGames.length < 2) return setLoading(true) setError(null) try { const ids = selectedGames.map(g => g.id).join(",") const res = await fetch(`/api/compare/games?ids=${ids}`) if (!res.ok) { const data = await res.json() throw new Error(data.error || "Failed to fetch comparison") } const data = await res.json() setComparisonData(data.games || []) } catch (err: unknown) { setError(err instanceof Error ? err.message : "Failed to load comparison") } finally { setLoading(false) } }, [selectedGames]) const canCompare = selectedGames.length >= 2 return (
Compare Games Select 2-4 games to compare performance stats side by side. {/* Game selector */} {/* Compare button */}
{!canCompare && selectedGames.length > 0 && ( Select at least 2 games )}
{/* Error */} {error && (

{error}

)} {/* Results */} {comparisonData.length >= 2 && ( {/* Stats comparison table */}

Stats Overview

{/* FPS comparison bar chart */}

FPS by Device

{/* Stability radar */}

Performance Profile

)} {/* Empty state */} {comparisonData.length === 0 && !loading && (

Select games above to start comparing

)}
) }