"use client"; import { useRouter, useSearchParams } from "next/navigation"; import { Suspense, useEffect, useState } from "react"; import { ArrowLeft, HelpCircle, Clock, XCircle, OctagonX, RotateCw, } from "lucide-react"; import DestructibleAlert from "@/components/DestructibleAlert"; import BackgroundWrapper from "@/components/BackgroundWrapper"; import { API_URL, getToken } from "@/lib/auth"; import { useExam } from "@/context/ExamContext"; import { Test } from "@/types/exam"; import { Metadata } from "@/types/exam"; function PretestPageContent() { const router = useRouter(); const searchParams = useSearchParams(); const { startExam } = useExam(); const [examData, setExamData] = useState(); // Get params from URL search params const id = searchParams.get("test_id") || ""; const typeParam = searchParams.get("type"); const type = typeParam === "mock" || typeParam === "subject" || typeParam === "topic" ? typeParam : null; const [metadata, setMetadata] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(); useEffect(() => { async function fetchQuestions() { if (!id || !type) return; try { setLoading(true); const token = await getToken(); const questionResponse = await fetch(`${API_URL}/tests/${type}/${id}`, { method: "GET", headers: { authorization: `Bearer ${token}`, }, }); if (!questionResponse.ok) { throw new Error("Failed to fetch questions"); } const data = await questionResponse.json(); const fetchedMetadata: Metadata = data.metadata; const fetchedQuestions: Test = data.questions; setMetadata(fetchedMetadata); setExamData(fetchedQuestions); } catch (error) { console.error(error); setError(error instanceof Error ? error.message : "An error occurred"); } finally { setLoading(false); } } fetchQuestions(); }, [id, type]); if (error) { return (
} />
); } if (loading) { return (

Loading...

); } function handleStartExam() { if (!examData) return; router.push( `/exam/${id}?type=${type}&test_id=${metadata?.test_id}&attempt_id=${metadata?.attempt_id}` ); } return (
{metadata ? (

{metadata.name}

Rating: 8 / 10

{metadata.num_questions}

Multiple Choice Questions

{String(metadata.time_limit_minutes)} mins

Time Taken

{metadata.deduction} marks

From each wrong answer

Ready yourself!

You must complete this test in one session - make sure your internet connection is reliable.

There is negative marking for the wrong answer.

The more you answer correctly, the better chance you have of winning a badge.

You can retake this test however many times you want. But, you will earn points only once.

) : (

Loading...

)}
{/* */}
); } export default function PretestPage() { return (

Loading...

} >
); }