'use client' import React, { useState, useEffect } from 'react' import { useRouter } from 'next/navigation' import { Brain, Plus, Clock, Trophy, Users, Sparkles, Crown, Target, Play, Globe, Lock } from 'lucide-react' interface Quiz { _id: string id: string title: string description: string difficulty: string questions: any[] generated_by?: string created_at: string total_points: number } interface QuizRoom { room_id: string room_code: string title: string host_name: string is_private: boolean status: string participants_count: number questions_count: number questions_by_difficulty: { easy: number medium: number hard: number } } export default function QuizzesPage() { const [activeTab, setActiveTab] = useState<'traditional' | 'rooms' | 'adaptive'>('rooms') const [quizzes, setQuizzes] = useState([]) const [publicRooms, setPublicRooms] = useState([]) const [loading, setLoading] = useState(true) const [aiAvailable, setAiAvailable] = useState(false) const router = useRouter() useEffect(() => { if (activeTab === 'traditional') { fetchTraditionalQuizzes() } else if (activeTab === 'rooms') { fetchPublicRooms() } }, [activeTab]) const fetchTraditionalQuizzes = async () => { setLoading(true) try { const response = await fetch('http://127.0.0.1:5000/api/quizzes') const data = await response.json() if (data.success) { setQuizzes(data.quizzes) setAiAvailable(data.ai_available) } } catch (err) { console.error('Failed to fetch quizzes:', err) } finally { setLoading(false) } } const fetchPublicRooms = async () => { setLoading(true) try { const response = await fetch('http://127.0.0.1:5000/api/quizzes/public-rooms') const data = await response.json() if (data.success) { setPublicRooms(data.public_rooms) } } catch (err) { console.error('Failed to fetch public rooms:', err) } finally { setLoading(false) } } const getDifficultyColor = (difficulty: string) => { switch (difficulty.toLowerCase()) { case 'easy': return 'text-green-400 bg-green-900' case 'medium': return 'text-yellow-400 bg-yellow-900' case 'hard': return 'text-red-400 bg-red-900' default: return 'text-gray-400 bg-gray-700' } } const getStatusColor = (status: string) => { switch (status) { case 'waiting': return 'text-yellow-400 bg-yellow-900' case 'active': return 'text-green-400 bg-green-900' case 'completed': return 'text-gray-400 bg-gray-700' default: return 'text-gray-400 bg-gray-700' } } if (loading && activeTab === 'traditional' && quizzes.length === 0) { return (

Loading quizzes...

) } return (
{/* Header */}

🧠 OpenLearnX Quiz Platform

Experience adaptive quizzes with AI-powered questions and real-time difficulty adjustment

{/* Tab Navigation */}
{[ { id: 'rooms', label: 'Live Quiz Rooms', icon: Users, description: 'Join or host live quizzes' }, { id: 'adaptive', label: 'Adaptive Quiz', icon: Brain, description: 'AI-powered adaptive difficulty' }, { id: 'traditional', label: 'Traditional Quizzes', icon: Target, description: 'Fixed question sets' } ].map(tab => ( ))}
{/* Live Quiz Rooms Tab */} {activeTab === 'rooms' && (
{/* Action Buttons */}
{/* Public Rooms Grid */}

🌍 Public Quiz Rooms

{loading ? (

Loading rooms...

) : publicRooms.length === 0 ? (

No Public Rooms Available

Be the first to create a public quiz room!

) : (
{publicRooms.map((room) => (
{/* Room Header */}

{room.title}

Host: {room.host_name}

{room.status}
{/* Room Stats */}
{room.participants_count}
Participants
{room.questions_count}
Questions
{/* Difficulty Breakdown */}
Easy: {room.questions_by_difficulty?.easy || 0} Medium: {room.questions_by_difficulty?.medium || 0} Hard: {room.questions_by_difficulty?.hard || 0}
{/* Room Code */}
Code: {room.room_code}
{/* Join Button */}
))}
)}
)} {/* Adaptive Quiz Tab */} {activeTab === 'adaptive' && (

🧠 Adaptive AI Quiz

Experience an intelligent quiz that adapts to your skill level in real-time using our trained CNN model.

Adaptive Difficulty

Questions adjust based on your performance

AI Predictions

See how our AI model would answer

Smart Analytics

Track performance across difficulty levels

)} {/* Traditional Quizzes Tab */} {activeTab === 'traditional' && (
{/* AI Status & Create Buttons */}
{aiAvailable && ( )}
{/* AI Status Banner */} {aiAvailable && (

🤖 AI Service Active

Our trained CNN model is ready to generate intelligent quizzes and provide feedback

)} {/* Traditional Quizzes Grid */} {quizzes.length === 0 ? (

No Traditional Quizzes Yet

Create your first quiz or generate one using AI

{aiAvailable && ( )}
) : (
{quizzes.map((quiz) => (
router.push(`/quizzes/${quiz.id}`)} > {/* Quiz Header */}

{quiz.generated_by === 'AI' && ( )} {quiz.title}

{quiz.difficulty}
{/* Description */}

{quiz.description}

{/* Stats */}
{quiz.questions?.length || 0} questions {quiz.total_points} pts
{quiz.generated_by === 'AI' && (
AI Generated
)}
{/* Date */}
Created {new Date(quiz.created_at).toLocaleDateString()}
))}
)}
)}
) }