"use client"; import { useRouter } from "next/navigation"; import { useExam, useExamResults } from "@/context/ExamContext"; import { useEffect, useState } from "react"; import React from "react"; import { ArrowLeft } from "lucide-react"; import SlidingGallery from "@/components/SlidingGallery"; import QuestionItem from "@/components/QuestionItem"; import { getResultViews } from "@/lib/gallery-views"; export default function ResultsPage() { const router = useRouter(); const { clearExam, isExamCompleted, getApiResponse, currentAttempt, isHydrated, } = useExam(); const [isLoading, setIsLoading] = useState(true); useEffect(() => { // Wait for hydration first if (!isHydrated) return; // Check if exam is completed, redirect if not if (!isExamCompleted() || !currentAttempt) { router.push("/unit"); return; } // If we have exam results, we're ready to render if (currentAttempt?.answers) { setIsLoading(false); } }, [isExamCompleted, currentAttempt, isHydrated, router]); const handleBackToHome = () => { clearExam(); router.push("/unit"); }; // Show loading screen while initializing or if no exam results if (isLoading || !currentAttempt) { return (

Loading...

); } const apiResponse = getApiResponse(); const timeTaken = currentAttempt.endTime && currentAttempt.startTime ? Math.round( (currentAttempt.endTime.getTime() - currentAttempt.startTime.getTime()) / 1000 / 60 ) : 0; const views = getResultViews(currentAttempt); // Get score-based message const getScoreMessage = () => { if (!currentAttempt.score || currentAttempt.score < 30) return "Try harder!"; if (currentAttempt.score < 70) return "Getting Better"; return "You did great!"; }; return (

{getScoreMessage()}

{/* Score Display */} {apiResponse?.questions && (

Solutions

{apiResponse.questions.map((question) => ( ))}
)}
); }