"use client"; import { useRouter, useSearchParams } from "next/navigation"; import { useEffect, useState } from "react"; import { ArrowLeft, HelpCircle, Clock, XCircle } from "lucide-react"; import DestructibleAlert from "@/components/DestructibleAlert"; import BackgroundWrapper from "@/components/BackgroundWrapper"; import { API_URL } from "@/lib/auth"; import { useExam } from "@/context/ExamContext"; import { Exam } from "@/types/exam"; interface Metadata { metadata: { quantity: number; type: string; duration: number; marking: string; }; } export default function PretestPage() { const router = useRouter(); const searchParams = useSearchParams(); const [examData, setExamData] = useState(); const { startExam, setCurrentExam } = useExam(); // Get params from URL search params const name = searchParams.get("name") || ""; const id = searchParams.get("id") || ""; const title = searchParams.get("title") || ""; const rating = searchParams.get("rating") || ""; const [metadata, setMetadata] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); async function fetchQuestions() { if (!id) return; try { setLoading(true); const questionResponse = await fetch(`${API_URL}/mock/${id}`, { method: "GET", }); if (!questionResponse.ok) { throw new Error("Failed to fetch questions"); } const data = await questionResponse.json(); const fetchedMetadata: Metadata = data; setExamData(data); setMetadata(fetchedMetadata); } catch (error) { console.error(error); setError(error instanceof Error ? error.message : "An error occurred"); } finally { setLoading(false); } } useEffect(() => { if (id) { fetchQuestions(); } }, [id]); if (error) { return (
{/* */}
); } function handleStartExam() { setCurrentExam(examData); startExam(examData); // Pass examData directly router.push(`/exam/${id}?time=${metadata?.metadata.duration}`); } return (
{metadata ? (

{title}

Rating: {rating} / 10

{metadata.metadata.quantity}

{metadata.metadata.type}

{metadata.metadata.duration} mins

Time Taken

{metadata.metadata.marking}

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...

)}
{/* */}
); }