import { useState, useEffect } from "react"; import { supabase } from "@/integrations/supabase/client"; import { Eye } from "lucide-react"; import { Dialog, DialogContent, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { useTranslation } from "@/hooks/useTranslation"; import { GuessDescription } from "@/components/game/guess-display/GuessDescription"; interface GameResult { id: string; target_word: string; description: string; ai_guess: string; is_correct: boolean; } interface SentenceWord { word: string; provider: 'player' | 'ai'; } interface ComparisonDialogProps { isOpen: boolean; onClose: () => void; currentResult: GameResult | null; friendResult: GameResult | null; } const ComparisonDialog = ({ isOpen, onClose, currentResult, friendResult }: ComparisonDialogProps) => { const t = useTranslation(); const convertToSentenceWords = (description: string): SentenceWord[] => { return description.split(' ').map((word, index) => ({ word, provider: index % 2 === 0 ? 'player' as const : 'ai' as const })); }; return ( {currentResult?.target_word}
{friendResult && (

{t.game.review.yourDescription}

)}

{t.guess.aiGuessedDescription}: {currentResult?.ai_guess}

{friendResult && (

{t.game.review.friendDescription}

{t.guess.aiGuessedDescription}: {friendResult.ai_guess}

)}
); }; export const GameDetailsView = ({ gameResults = [], fromSession }: { gameResults: GameResult[], fromSession?: string | null }) => { const [friendResults, setFriendResults] = useState([]); const [selectedResult, setSelectedResult] = useState(null); const t = useTranslation(); useEffect(() => { const fetchFriendResults = async () => { if (!fromSession) return; const { data, error } = await supabase .from('game_results') .select('*') .eq('session_id', fromSession) .order('created_at', { ascending: true }); if (!error && data) { console.log('Friend results:', data); setFriendResults(data); } }; fetchFriendResults(); }, [fromSession]); const getFriendResult = (targetWord: string) => { return friendResults.find(r => r.target_word === targetWord) || null; }; const getWordCount = (description?: string) => { return description?.split(' ').length || 0; }; return (
{friendResults.length > 0 && ( )} {gameResults.map((result) => { const friendResult = getFriendResult(result.target_word); return ( setSelectedResult(result)} > {friendResults.length > 0 && ( )} ); })}
{t.game.round} {friendResults.length > 0 ? t.game.review.yourWords : t.game.review.words} {t.game.review.friendWords} {t.game.review.details}
{result.target_word} {result.is_correct ? '✅' : '❌'} {getWordCount(result.description)} {friendResult ? `${friendResult.is_correct ? '✅' : '❌'} ${getWordCount(friendResult.description)}` : '-'}
setSelectedResult(null)} currentResult={selectedResult} friendResult={selectedResult ? getFriendResult(selectedResult.target_word) : null} />
); };