import { useEffect, useRef } from 'react'; import { Animated, Pressable, Text, View } from 'react-native'; import { useTranslation } from 'react-i18next'; import * as Haptics from 'expo-haptics'; import { useColors } from '../../lib/theme'; export type GameOverScreenProps = { score: number; bestScore: number; gameName: string; onRetry: () => void; onExit: () => void; isNewBest?: boolean; }; const MOTIVATIONAL_KEYS = [ 'gameOver.motivational_0', 'gameOver.motivational_1', 'gameOver.motivational_2', 'gameOver.motivational_3', 'gameOver.motivational_4', ]; export function GameOverScreen({ score, bestScore, gameName, onRetry, onExit, isNewBest = false, }: GameOverScreenProps) { const { t } = useTranslation(); const colors = useColors(); const slideAnim = useRef(new Animated.Value(40)).current; const fadeAnim = useRef(new Animated.Value(0)).current; useEffect(() => { Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success).catch(() => {}); Animated.parallel([ Animated.spring(slideAnim, { toValue: 0, useNativeDriver: true, tension: 60, friction: 10 }), Animated.timing(fadeAnim, { toValue: 1, duration: 220, useNativeDriver: true }), ]).start(); }, []); const motivationalKey = MOTIVATIONAL_KEYS[score % MOTIVATIONAL_KEYS.length]!; const fmt = (n: number) => String(n).padStart(5, '0'); return ( {/* Backdrop */} {/* Card */} {/* Title row */} {t('gameOver.title')} {gameName} {/* Score row */} {/* Score */} {fmt(score)} {t('gameOver.score')} {/* Best */} {fmt(Math.max(score, bestScore))} {isNewBest ? t('gameOver.newBest') : t('gameOver.best')} {/* Motivational text */} {t(motivationalKey)} {/* Buttons */} { Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Medium).catch(() => {}); onRetry(); }} style={({ pressed }) => ({ flex: 1, paddingVertical: 13, paddingHorizontal: 16, borderRadius: 12, backgroundColor: '#007AFF', alignItems: 'center', opacity: pressed ? 0.75 : 1, })} > {t('gameOver.retry')} { Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light).catch(() => {}); onExit(); }} style={({ pressed }) => ({ flex: 1, paddingVertical: 13, paddingHorizontal: 16, borderRadius: 12, backgroundColor: colors.surfaceElevated, alignItems: 'center', opacity: pressed ? 0.75 : 1, })} > {t('gameOver.exit')} ); }