import { useEffect, useState } from "react"; import { Outlet, replace, useParams } from "react-router-dom"; import { api } from "../../../utils/api"; import { useAuthStore } from "../../../stores/authStore"; import type { PracticeSheet } from "../../../types/sheet"; import { CircleQuestionMark, Clock, Layers, Loader, Loader2, Tag, } from "lucide-react"; import { Carousel, CarouselContent, CarouselItem, type CarouselApi, } from "../../../components/ui/carousel"; import { Button } from "../../../components/ui/button"; import { useNavigate } from "react-router-dom"; export const Pretest = () => { const user = useAuthStore((state) => state.user); const { sheetId } = useParams<{ sheetId: string }>(); const [carouselApi, setCarouselApi] = useState(); const [current, setCurrent] = useState(0); const [count, setCount] = useState(0); const navigate = useNavigate(); const [practiceSheet, setPracticeSheet] = useState( null, ); function handleStartTest(sheetId: string) { if (!sheetId) { console.error("Sheet ID is required to start the test."); return; } navigate(`/student/practice/${sheetId}/test`, { replace: true }); } useEffect(() => { if (!user) return; async function fetchPracticeSheet(sheetId: string) { const authStorage = localStorage.getItem("auth-storage"); if (!authStorage) { console.error("authStorage not found in local storage"); return; } const { state: { token }, } = JSON.parse(authStorage); if (!token) { console.error("Token not found in authStorage"); return; } const data = await api.getPracticeSheetById(token, sheetId); setPracticeSheet(data); } fetchPracticeSheet(sheetId!); }, [sheetId]); useEffect(() => { if (!carouselApi) { return; } setCount(carouselApi.scrollSnapList().length); setCurrent(carouselApi.selectedScrollSnap() + 1); carouselApi.on("select", () => { setCurrent(carouselApi.selectedScrollSnap() + 1); }); }, [carouselApi]); return (

{practiceSheet?.title}

{practiceSheet?.description}

{practiceSheet ? (

{practiceSheet?.time_limit}

Minutes

{practiceSheet?.modules.length}

Modules

{practiceSheet?.questions_count}

Questions

) : (
)} {practiceSheet ? ( practiceSheet.modules.length > 0 ? ( practiceSheet.modules.map((module, index) => (

Section {Math.floor(index / 2) + 1}

{module.title}

{module.duration}

Minutes

{module.questions.length}

Questions

{module.section}

Type

)) ) : (

No modules available.

) ) : (

Loading...

)}
{practiceSheet?.modules.map((_, index) => (
))}

This practice sheet will help you prepare for the SAT. Take your time and do your best!

); };