import React, { useState } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { X, Trash2, Play, BrainCircuit, PenTool, Loader2, Calendar } from 'lucide-react'; import { QuizListItem } from '../types'; interface QuizLibraryProps { isOpen: boolean; onClose: () => void; quizzes: QuizListItem[]; loading: boolean; loadingQuizId: string | null; deletingQuizId: string | null; error: string | null; onLoadQuiz: (id: string) => void; onDeleteQuiz: (id: string) => void; onRetry: () => void; } export const QuizLibrary: React.FC = ({ isOpen, onClose, quizzes, loading, loadingQuizId, deletingQuizId, error, onLoadQuiz, onDeleteQuiz, onRetry, }) => { const [confirmDeleteId, setConfirmDeleteId] = useState(null); const isAnyOperationInProgress = loading || !!loadingQuizId || !!deletingQuizId; const handleDeleteClick = (e: React.MouseEvent, id: string) => { e.stopPropagation(); setConfirmDeleteId(id); }; const confirmDelete = async (e: React.MouseEvent) => { e.stopPropagation(); if (confirmDeleteId) { try { await onDeleteQuiz(confirmDeleteId); setConfirmDeleteId(null); } catch { setConfirmDeleteId(null); } } }; const cancelDelete = (e: React.MouseEvent) => { e.stopPropagation(); setConfirmDeleteId(null); }; const formatDate = (dateString: string) => { try { return new Date(dateString).toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric', }); } catch (e) { return dateString; } }; return ( {isOpen && ( <> e.stopPropagation()} className="bg-white w-full max-w-2xl max-h-[80vh] flex flex-col rounded-[2rem] shadow-[0_10px_0_rgba(0,0,0,0.1)] border-4 border-white/50 relative overflow-hidden" >

My Library

Select a quiz to play

{loading && (

Loading your quizzes...

)} {!loading && error && (

{error}

)} {!loading && !error && quizzes.length === 0 && (

No saved quizzes yet

Create or generate a quiz to save it here!

)} {!loading && !error && quizzes.map((quiz) => ( !isAnyOperationInProgress && onLoadQuiz(quiz.id)} >
{quiz.source === 'ai_generated' ? ( AI ) : ( Manual )} {formatDate(quiz.createdAt)}

{quiz.title}

{quiz.questionCount} question{quiz.questionCount !== 1 ? 's' : ''} {quiz.aiTopic && • Topic: {quiz.aiTopic}}

{loadingQuizId === quiz.id ? (
) : deletingQuizId === quiz.id ? (
) : confirmDeleteId === quiz.id ? (
e.stopPropagation()}>
) : ( <>
)}
))}
)}
); };