import React, { useState, useEffect } from 'react' import { testingService } from '../../services/api' import { QuestionCard } from './QuestionCard' import { InstantFeedback } from './InstantFeedback' import { ProgressTracker } from './ProgressTracker' import toast from 'react-hot-toast' interface Question { id: string question: string options: string[] difficulty: number subject: string } interface FeedbackData { correct: boolean confidence_score: number explanation: string correct_answer: string current_score: number total_answered: number } export const AdaptiveTest: React.FC = () => { const [sessionId, setSessionId] = useState('') const [currentQuestion, setCurrentQuestion] = useState(null) const [feedback, setFeedback] = useState(null) const [questionNumber, setQuestionNumber] = useState(1) const [totalQuestions] = useState(10) const [isLoading, setIsLoading] = useState(false) const [testCompleted, setTestCompleted] = useState(false) const [selectedSubject, setSelectedSubject] = useState('Mathematics') const subjects = ['Mathematics', 'Geography', 'Literature', 'Science'] const startTest = async () => { setIsLoading(true) setTestCompleted(false) setQuestionNumber(1) setFeedback(null) try { const data = await testingService.startTest(selectedSubject) setSessionId(data.session_id) setCurrentQuestion(data.question) toast.success('Test started! Good luck!') } catch (error) { console.error('Failed to start test:', error) toast.error('Failed to start test. Please try again.') } finally { setIsLoading(false) } } const submitAnswer = async (answerIndex: number) => { if (!currentQuestion || !sessionId) return setIsLoading(true) try { const data = await testingService.submitAnswer(sessionId, currentQuestion.id, answerIndex) setFeedback(data.feedback) // Show feedback, then proceed setTimeout(() => { if (data.test_completed) { setTestCompleted(true) toast.success('Test completed! Check your results.') } else if (data.next_question) { setCurrentQuestion(data.next_question) setQuestionNumber(prev => prev + 1) setFeedback(null) } }, 3000) } catch (error) { console.error('Failed to submit answer:', error) toast.error('Failed to submit answer. Please try again.') } finally { setIsLoading(false) } } if (!sessionId && !isLoading) { return (

OpenLearnX Adaptive Test

Experience personalized learning with our adaptive testing system that adjusts to your performance in real-time.

) } if (testCompleted) { return (
🎉

Test Completed!

Congratulations! You've completed the adaptive test. Your performance has been analyzed and saved.

) } return (
{currentQuestion && ( )}
{feedback ? ( ) : (
🤔

Select your answer to receive instant feedback with detailed explanations!

)}
) }