|
| 1 | +import React from 'react' |
| 2 | +import styled, { keyframes } from 'styled-components' |
| 3 | +import { ScenarioResult, Scenario } from '../../data/trainingScenarios' |
| 4 | +import { useLocalization } from '../../contexts/Language/LanguageProvider' |
| 5 | + |
| 6 | +interface FeedbackOverlayProps { |
| 7 | + result: ScenarioResult |
| 8 | + scenario: Scenario |
| 9 | + onNext: () => void |
| 10 | + isLastBeforeResults?: boolean |
| 11 | +} |
| 12 | + |
| 13 | +const FeedbackOverlay: React.FC<FeedbackOverlayProps> = ({ |
| 14 | + result, |
| 15 | + scenario, |
| 16 | + onNext, |
| 17 | + isLastBeforeResults, |
| 18 | +}) => { |
| 19 | + const { locals } = useLocalization() |
| 20 | + const gradeLabel = locals.gradeLabels[result.grade.toLowerCase().replace('+', 'p') as keyof typeof locals.gradeLabels] |
| 21 | + || locals.gradeLabels[result.grade === 'A+' ? 'ap' : result.grade.toLowerCase() as keyof typeof locals.gradeLabels] |
| 22 | + |
| 23 | + return ( |
| 24 | + <Container> |
| 25 | + <ResultBadge $correct={result.correct}> |
| 26 | + {result.reactionMs === 0 ? locals.timesUp : result.correct ? locals.correctAnswer : locals.wrongAnswer} |
| 27 | + </ResultBadge> |
| 28 | + |
| 29 | + {result.correct && ( |
| 30 | + <StatsRow> |
| 31 | + <Stat> |
| 32 | + <StatLabel>{locals.reactionTime}</StatLabel> |
| 33 | + <StatValue>{result.reactionMs}{locals.milliseconds}</StatValue> |
| 34 | + </Stat> |
| 35 | + <Stat> |
| 36 | + <StatLabel>Grade</StatLabel> |
| 37 | + <GradeValue $grade={result.grade}>{result.grade} — {gradeLabel}</GradeValue> |
| 38 | + </Stat> |
| 39 | + {result.score > 0 && ( |
| 40 | + <Stat> |
| 41 | + <PointsEarned> |
| 42 | + {locals.pointsEarned.replace('{0}', String(result.score))} |
| 43 | + </PointsEarned> |
| 44 | + </Stat> |
| 45 | + )} |
| 46 | + </StatsRow> |
| 47 | + )} |
| 48 | + |
| 49 | + <ExplanationBox> |
| 50 | + <ExplanationLabel>{locals.explanationLabel}</ExplanationLabel> |
| 51 | + <ExplanationText>{scenario.explanation}</ExplanationText> |
| 52 | + </ExplanationBox> |
| 53 | + |
| 54 | + <NextButton onClick={onNext}> |
| 55 | + {isLastBeforeResults ? 'See Results' : locals.nextScenario} → |
| 56 | + </NextButton> |
| 57 | + </Container> |
| 58 | + ) |
| 59 | +} |
| 60 | + |
| 61 | +const fadeSlide = keyframes` |
| 62 | + from { opacity: 0; transform: translateY(16px); } |
| 63 | + to { opacity: 1; transform: translateY(0); } |
| 64 | +` |
| 65 | + |
| 66 | +const Container = styled.div` |
| 67 | + display: flex; |
| 68 | + flex-direction: column; |
| 69 | + align-items: center; |
| 70 | + gap: 1.25rem; |
| 71 | + animation: ${fadeSlide} 0.3s ease-out; |
| 72 | + max-width: 600px; |
| 73 | + margin: 0 auto; |
| 74 | + width: 100%; |
| 75 | +` |
| 76 | + |
| 77 | +const ResultBadge = styled.div<{ $correct: boolean }>` |
| 78 | + font-size: 1.8rem; |
| 79 | + font-weight: 900; |
| 80 | + font-family: 'Poppins', sans-serif; |
| 81 | + color: ${props => props.$correct ? '#4CAF50' : '#ff6b6b'}; |
| 82 | + text-shadow: 0 2px 8px ${props => props.$correct ? 'rgba(76,175,80,0.3)' : 'rgba(255,107,107,0.3)'}; |
| 83 | +` |
| 84 | + |
| 85 | +const StatsRow = styled.div` |
| 86 | + display: flex; |
| 87 | + gap: 1.5rem; |
| 88 | + flex-wrap: wrap; |
| 89 | + justify-content: center; |
| 90 | +` |
| 91 | + |
| 92 | +const Stat = styled.div` |
| 93 | + display: flex; |
| 94 | + flex-direction: column; |
| 95 | + align-items: center; |
| 96 | + gap: 0.2rem; |
| 97 | +` |
| 98 | + |
| 99 | +const StatLabel = styled.span` |
| 100 | + font-size: 0.7rem; |
| 101 | + color: ${props => props.theme.subtleText}; |
| 102 | + text-transform: uppercase; |
| 103 | + letter-spacing: 0.08em; |
| 104 | +` |
| 105 | + |
| 106 | +const StatValue = styled.span` |
| 107 | + font-size: 1.1rem; |
| 108 | + font-weight: 700; |
| 109 | + color: ${props => props.theme.titleColor}; |
| 110 | +` |
| 111 | + |
| 112 | +const gradeColor = (grade: string) => { |
| 113 | + if (grade === 'A+' || grade === 'A') return '#4CAF50' |
| 114 | + if (grade === 'B') return '#8BC34A' |
| 115 | + if (grade === 'C') return '#FF9800' |
| 116 | + if (grade === 'D') return '#FF5722' |
| 117 | + return '#ff6b6b' |
| 118 | +} |
| 119 | + |
| 120 | +const GradeValue = styled.span<{ $grade: string }>` |
| 121 | + font-size: 1rem; |
| 122 | + font-weight: 700; |
| 123 | + color: ${props => gradeColor(props.$grade)}; |
| 124 | +` |
| 125 | + |
| 126 | +const PointsEarned = styled.span` |
| 127 | + font-size: 1.4rem; |
| 128 | + font-weight: 900; |
| 129 | + background: linear-gradient(135deg, #ffd700, #ff9800); |
| 130 | + -webkit-background-clip: text; |
| 131 | + -webkit-text-fill-color: transparent; |
| 132 | +` |
| 133 | + |
| 134 | +const ExplanationBox = styled.div` |
| 135 | + background: ${props => props.theme.cardBackground}; |
| 136 | + border: 1px solid ${props => props.theme.cardBorder}; |
| 137 | + border-radius: 12px; |
| 138 | + padding: 1.25rem 1.5rem; |
| 139 | + width: 100%; |
| 140 | +` |
| 141 | + |
| 142 | +const ExplanationLabel = styled.div` |
| 143 | + font-size: 0.75rem; |
| 144 | + font-weight: 700; |
| 145 | + color: ${props => props.theme.accent}; |
| 146 | + text-transform: uppercase; |
| 147 | + letter-spacing: 0.1em; |
| 148 | + margin-bottom: 0.5rem; |
| 149 | +` |
| 150 | + |
| 151 | +const ExplanationText = styled.p` |
| 152 | + margin: 0; |
| 153 | + font-size: 0.95rem; |
| 154 | + line-height: 1.7; |
| 155 | + color: ${props => props.theme.cardText}; |
| 156 | +` |
| 157 | + |
| 158 | +const NextButton = styled.button` |
| 159 | + background: linear-gradient(135deg, #ffd700, #ff9800); |
| 160 | + color: #1a1a1a; |
| 161 | + border: none; |
| 162 | + border-radius: 12px; |
| 163 | + padding: 0.85rem 2.5rem; |
| 164 | + font-size: 1rem; |
| 165 | + font-weight: 700; |
| 166 | + cursor: pointer; |
| 167 | + transition: all 0.2s ease; |
| 168 | + font-family: 'Poppins', sans-serif; |
| 169 | +
|
| 170 | + &:hover { |
| 171 | + transform: translateY(-2px); |
| 172 | + box-shadow: 0 6px 20px rgba(255, 215, 0, 0.4); |
| 173 | + } |
| 174 | +` |
| 175 | + |
| 176 | +export default FeedbackOverlay |
0 commit comments