1+ import { useMemo } from "react" ;
2+
3+ import { FaRedo } from "react-icons/fa" ;
4+
5+ import { PieChart , Pie , Cell , ResponsiveContainer } from "recharts" ;
6+ import "../styles/FinalScreen.css" ;
7+
8+ export default function FinalScreen ( { data, gameMode, onClick } ) {
9+ const stats = useMemo ( ( ) => {
10+ const totalWords = data . length
11+ const correctWords = data . filter ( w => w . correctWord ) . length
12+ const wrongWords = totalWords - correctWords
13+ const totalLetters = data . reduce ( ( acc , w ) => acc + w . letterCorrect + w . letterWrong , 0 )
14+ const correctLetters = data . reduce ( ( acc , w ) => acc + w . letterCorrect , 0 )
15+ const wrongLetters = data . reduce ( ( acc , w ) => acc + w . letterWrong , 0 )
16+ const accuracy = totalLetters > 0 ? Math . round ( ( correctLetters / totalLetters ) * 100 ) : 0
17+ const wpmNeto = data . wpmNeto || 0
18+ const wpmBruto = data . wpmBruto || 0
19+ const time = data . time
20+
21+ return { totalWords, correctWords, wrongWords, totalLetters, correctLetters,
22+ wrongLetters, accuracy, wpmNeto, wpmBruto, time }
23+ } , [ data ] )
24+
25+ const getMotivationalMessage = ( wpmNeto ) => {
26+ if ( wpmNeto >= 100 ) return "¡Perfecto, eres muy veloz! 🔥"
27+ if ( wpmNeto >= 70 ) return "¡Gran trabajo, lo haces genial! 💪"
28+ if ( wpmNeto >= 50 ) return "¡Bien hecho! Sigue practicando ✨"
29+ if ( wpmNeto >= 40 && wpmNeto < 50 ) return "No está mal, pero puedes mejorar 😉"
30+ if ( wpmNeto < 40 ) return "¡No te rindas! Poco a poco mejorarás 🆙"
31+ return "¡No te rindas! Cada error cuenta 💡"
32+ }
33+
34+ const donutData = [
35+ { name : "Correctas" , value : stats . accuracy } ,
36+ { name : "Incorrectas" , value : 100 - stats . accuracy }
37+ ]
38+
39+ const COLORS = [ "#4aff91" , "#ff4b6b" ]
40+
41+ return (
42+ < div className = "final-screen-graph" >
43+
44+ < div className = "donut-section horizontal" >
45+ < div className = "donut-left" >
46+ < div className = "donut-container" >
47+ < ResponsiveContainer width = { 200 } height = { 200 } >
48+ < PieChart >
49+ < Pie
50+ data = { donutData }
51+ innerRadius = { 70 }
52+ outerRadius = { 90 }
53+ dataKey = "value"
54+ startAngle = { 90 }
55+ endAngle = { - 270 }
56+ >
57+ { donutData . map ( ( entry , index ) => (
58+ < Cell key = { `cell-${ index } ` } fill = { COLORS [ index % COLORS . length ] } />
59+ ) ) }
60+ </ Pie >
61+ </ PieChart >
62+ </ ResponsiveContainer >
63+ < div className = "donut-center" >
64+ < span className = "donut-value" > { stats . accuracy } %</ span >
65+ < span className = "donut-label" > PRECISION</ span >
66+ </ div >
67+ </ div >
68+ </ div >
69+
70+ < div className = "donut-right" >
71+ < div className = "motivational-message" >
72+ { getMotivationalMessage ( stats . wpmNeto ) }
73+ </ div >
74+ < div className = "wpm-panel horizontal" >
75+ < div className = "metric" >
76+ < span className = "label" > WPM</ span >
77+ < span className = "value" > { stats . wpmNeto } </ span >
78+ </ div >
79+ < div className = "metric" >
80+ < span className = "label" > WPM raw</ span >
81+ < span className = "value" > { stats . wpmBruto } </ span >
82+ </ div >
83+ </ div >
84+ </ div >
85+ </ div >
86+
87+ < div className = "extra-stats" >
88+ < div className = "stat-card accuracy" >
89+ < span className = "icon" > 🎮</ span >
90+ < span className = "label" > Modo de juego</ span >
91+ < span className = "value" > { gameMode } </ span >
92+ </ div >
93+ < div className = "stat-card time" >
94+ < span className = "icon" > ⏱️</ span >
95+ < span className = "label" > Tiempo</ span >
96+ < span className = "value" > { stats . time } s</ span >
97+ </ div >
98+ < div className = "stat-card total" >
99+ < span className = "icon" > 🔢</ span >
100+ < span className = "label" > Total letras</ span >
101+ < span className = "value" > { stats . totalLetters } </ span >
102+ </ div >
103+ < div className = "stat-card correct" >
104+ < span className = "icon" > ✅</ span >
105+ < span className = "label" > Letras correctas</ span >
106+ < span className = "value" > { stats . correctLetters } </ span >
107+ </ div >
108+ < div className = "stat-card wrong" >
109+ < span className = "icon" > ❌</ span >
110+ < span className = "label" > Letras incorrectas</ span >
111+ < span className = "value" > { stats . wrongLetters } </ span >
112+ </ div >
113+ </ div >
114+
115+ < div className = "next-button-container" >
116+ < button className = "resetButtonFinal"
117+ onClick = { ( e ) => {
118+ e . currentTarget . blur ( )
119+ onClick ( )
120+ } }
121+ tabIndex = "-1" >
122+ < FaRedo className = "icon" />
123+ < span className = "text" > Reiniciar</ span >
124+ </ button >
125+ </ div >
126+ </ div >
127+ ) ;
128+ }
0 commit comments