'use client' import React, { useState } from 'react' import { useRouter } from 'next/navigation' import { Plus, Trash2, Save, ArrowLeft } from 'lucide-react' interface Question { question_text: string options: string[] correct_answer: string points: number } export default function CreateQuizPage() { const router = useRouter() const [quiz, setQuiz] = useState({ title: '', description: '', difficulty: 'medium' }) const [questions, setQuestions] = useState([]) const [currentQuestion, setCurrentQuestion] = useState({ question_text: '', options: ['', '', '', ''], correct_answer: '', points: 10 }) const [loading, setLoading] = useState(false) const addQuestion = () => { if (!currentQuestion.question_text || currentQuestion.options.some(opt => !opt.trim()) || !currentQuestion.correct_answer) { alert('Please fill all question fields') return } setQuestions([...questions, { ...currentQuestion }]) setCurrentQuestion({ question_text: '', options: ['', '', '', ''], correct_answer: '', points: 10 }) } const removeQuestion = (index: number) => { setQuestions(questions.filter((_, i) => i !== index)) } const createQuiz = async () => { if (!quiz.title || questions.length === 0) { alert('Please add a title and at least one question') return } setLoading(true) try { const quizData = { ...quiz, questions: questions.map((q, index) => ({ ...q, id: `q_${index}`, question_number: index + 1 })), total_points: questions.reduce((sum, q) => sum + q.points, 0), created_at: new Date().toISOString(), generated_by: 'manual' } const response = await fetch('http://127.0.0.1:5000/api/quizzes/', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(quizData) }) const data = await response.json() if (data.success) { alert('✅ Quiz created successfully!') router.push('/quizzes') } else { alert(`Error: ${data.error}`) } } catch (error) { alert('Network error: Could not create quiz') } finally { setLoading(false) } } return (
{/* Header */}

📝 Create New Quiz

{/* Quiz Details */}

Quiz Information

setQuiz(prev => ({...prev, title: e.target.value}))} className="w-full p-3 bg-white dark:bg-gray-700 text-gray-900 dark:text-white placeholder-gray-500 dark:placeholder-gray-400 rounded border border-gray-300 dark:border-gray-600 focus:ring-2 focus:ring-blue-500 focus:outline-none" />