"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 { Metadata } from "@/types/exam"; import { useExamStore } from "@/stores/examStore"; function PretestPageContent() { const router = useRouter(); const searchParams = useSearchParams(); // Get params from URL search params const id = searchParams.get("test_id") || ""; const type = searchParams.get("type"); const [metadata, setMetadata] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(); const { setStatus } = useExamStore(); 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; setMetadata(fetchedMetadata); } 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 (!metadata) return; setStatus("in-progress"); router.push( `/exam/exam-screen?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...

} >
); }