import React, { useState } from 'react'; import { X, BookOpen, Layers, ArrowRight, ArrowLeft, RotateCw, Loader2, Check } from 'lucide-react'; import { generateFlashcards } from '../api'; const FlashcardModal = ({ isOpen, onClose, notebookId }) => { const [status, setStatus] = useState('setup'); // setup, loading, studying const [difficulty, setDifficulty] = useState('medium'); const [numCards, setNumCards] = useState(10); const [cards, setCards] = useState([]); const [currentIndex, setCurrentIndex] = useState(0); const [isFlipped, setIsFlipped] = useState(false); if (!isOpen) return null; const handleGenerate = async () => { setStatus('loading'); try { const data = await generateFlashcards(notebookId, numCards, difficulty); setCards(data.flashcards || []); setStatus('studying'); setCurrentIndex(0); setIsFlipped(false); } catch (error) { console.error(error); // Handle error state? setStatus('setup'); // Reset for now } }; const handleNext = () => { if (currentIndex < cards.length - 1) { setIsFlipped(false); setTimeout(() => setCurrentIndex(prev => prev + 1), 150); } }; const handlePrev = () => { if (currentIndex > 0) { setIsFlipped(false); setTimeout(() => setCurrentIndex(prev => prev - 1), 150); } }; const handleFlip = () => setIsFlipped(!isFlipped); // Progress const progress = cards.length > 0 ? ((currentIndex + 1) / cards.length) * 100 : 0; return (
{/* Header */}

Flashcards

Master concepts through active recall

{/* Content */}
{status === 'setup' && (

Configure Your Session

Customize how you want to review this notebook.

{/* Difficulty */}
{['basic', 'medium', 'advanced'].map(level => ( ))}
{/* Card Count */}
{[5, 10, 15].map(count => ( ))}
)} {status === 'loading' && (

Reviewing Documents...

Identifying core concepts and crafting questions.

)} {status === 'studying' && cards.length > 0 && (
{/* Progress Bar */}
Card {currentIndex + 1} of {cards.length} {difficulty}
{/* Card Container - Perspective */}
{/* Front */}
Concept

{cards[currentIndex].front}

Click to flip

{/* Back */}
Explanation

{cards[currentIndex].back}

Swiped

{/* Nav */}
Use Space to Flip
)}
{/* Inline Styles for 3D flip if Tailwind plugins missing */}
); }; export default FlashcardModal;