'use client' import { useState } from 'react' import { Calendar, Loader2, X, Sparkles, CheckCircle2, BookOpen } from 'lucide-react' import { useLanguage } from '@/lib/i18n' import { cn } from '@/lib/utils' import { toast } from 'sonner' interface StudyDay { date: string noteIds: string[] noteTitles: string[] activity: string } export function StudyPlannerDialog({ notebookId, notebookName, onClose, }: { notebookId: string notebookName: string onClose: () => void }) { const { t } = useLanguage() const [examDate, setExamDate] = useState('') const [loading, setLoading] = useState(false) const [plan, setPlan] = useState<{ days: StudyDay[]; totalDays: number } | null>(null) const handleGenerate = async () => { if (!examDate) return setLoading(true) try { const res = await fetch('/api/ai/study-plan', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ notebookId, examDate }), }) const data = await res.json() if (!res.ok) { toast.error(data.errorKey === 'ai.featureLocked' ? (t('ai.featureLocked') || 'Plan requis') : (data.error || 'Erreur')) } else { setPlan(data) toast.success(t('wizard.studyPlanSuccess') || 'Planning créé ! Des rappels ont été ajoutés à vos notes.') window.dispatchEvent(new Event('ai-usage-changed')) } } catch (e: any) { toast.error(e.message || 'Erreur') } finally { setLoading(false) } } const today = new Date().toISOString().slice(0, 10) return (
{t('wizard.studyPlannerDesc') || `L'IA va créer un planning de révision pour le carnet "${notebookName}" basé sur la répétition espacée.`}
{t('wizard.studyPlanLoading') || 'Création du planning...'}
{day.activity}
{day.noteTitles.length > 0 && ({t('wizard.studyPlanReminders') || 'Des rappels ont été ajoutés automatiquement à vos notes.'}