import { useEffect, useRef } from 'react'; const scoreMessage = (pct) => { if (pct === 100) return 'Perfect score — absolutely outstanding! 🎉'; if (pct >= 80) return 'Excellent command of the material.'; if (pct >= 60) return 'Good effort — room to grow.'; if (pct >= 40) return 'Keep studying — you\'ll get there.'; return 'Review the material and try again.'; }; function ResultCard({ r, index }) { const correct = r.correct; return (
{correct ? '✓ Correct' : '✗ Incorrect'}
Q{index + 1}. {r.question}
{!correct && ( <>
Your Answer
{r.user_answer || '—'}
Correct Answer
{r.correct_answer}
{r.explanation && (
Explanation
{r.explanation}
)} {r.concept && (
✦ {r.concept}
)} )}
); } export default function ResultsView({ result, onReset }) { const { score, total, results } = result; const pct = total ? (score / total) * 100 : 0; const barRef = useRef(null); useEffect(() => { // Animate bar after mount const t = setTimeout(() => { if (barRef.current) barRef.current.style.width = `${pct.toFixed(1)}%`; }, 150); return () => clearTimeout(t); }, [pct]); return (
{/* Score Hero */}
{score}/{total}
Final Score
{scoreMessage(pct)}
{/* Detailed Review */}
Detailed Review
{results.map((r, i) => ( ))}
); }