'use client' import { useState, useTransition } from 'react' import { Bell, BellOff, CheckCircle2, Circle, Clock, AlertCircle, RefreshCw } from 'lucide-react' import { Note } from '@/lib/types' import { toggleReminderDone } from '@/app/actions/notes' import { useLanguage } from '@/lib/i18n' import { cn } from '@/lib/utils' import { useRouter } from 'next/navigation' interface RemindersPageProps { notes: Note[] } function formatReminderDate(date: Date | string, t: (key: string, params?: Record) => string, locale = 'fr-FR'): string { const d = new Date(date) const now = new Date() const today = new Date(now.getFullYear(), now.getMonth(), now.getDate()) const tomorrow = new Date(today) tomorrow.setDate(tomorrow.getDate() + 1) const noteDay = new Date(d.getFullYear(), d.getMonth(), d.getDate()) const timeStr = d.toLocaleTimeString(locale, { hour: '2-digit', minute: '2-digit' }) if (noteDay.getTime() === today.getTime()) return t('reminders.todayAt', { time: timeStr }) if (noteDay.getTime() === tomorrow.getTime()) return t('reminders.tomorrowAt', { time: timeStr }) return d.toLocaleDateString(locale, { weekday: 'long', day: 'numeric', month: 'long', hour: '2-digit', minute: '2-digit', }) } function ReminderCard({ note, onToggleDone, t }: { note: Note; onToggleDone: (id: string, done: boolean) => void; t: (key: string, params?: Record) => string }) { const now = new Date() const reminderDate = note.reminder ? new Date(note.reminder) : null const isOverdue = reminderDate && reminderDate < now && !note.isReminderDone const isDone = note.isReminderDone return (
{/* Done toggle */} {/* Content */}
{note.title && (

{note.title}

)}

{note.content}

{/* Reminder date badge */} {reminderDate && (
{isOverdue && !isDone ? ( ) : ( )} {formatReminderDate(reminderDate, t)} {note.reminderRecurrence && ( · {note.reminderRecurrence} )}
)}
) } function SectionTitle({ icon: Icon, label, count, color }: { icon: any; label: string; count: number; color: string }) { return (

{label}

{count}
) } export function RemindersPage({ notes: initialNotes }: RemindersPageProps) { const { t } = useLanguage() const router = useRouter() const [notes, setNotes] = useState(initialNotes) const [isPending, startTransition] = useTransition() const now = new Date() const upcoming = notes.filter(n => !n.isReminderDone && n.reminder && new Date(n.reminder) >= now) const overdue = notes.filter(n => !n.isReminderDone && n.reminder && new Date(n.reminder) < now) const done = notes.filter(n => n.isReminderDone) const handleToggleDone = (noteId: string, newDone: boolean) => { // Optimistic update setNotes(prev => prev.map(n => n.id === noteId ? { ...n, isReminderDone: newDone } : n)) startTransition(async () => { await toggleReminderDone(noteId, newDone) router.refresh() }) } if (notes.length === 0) { return (

{t('reminders.title') || 'Rappels'}

{t('reminders.empty') || 'Aucun rappel'}

{t('reminders.emptyDescription') || 'Ajoutez un rappel à une note pour le retrouver ici.'}

) } return (

{t('reminders.title') || 'Rappels'}

{isPending && ( )}
{/* En retard */} {overdue.length > 0 && (
{overdue.map(note => ( ))}
)} {/* À venir */} {upcoming.length > 0 && (
{upcoming.map(note => ( ))}
)} {/* Terminés */} {done.length > 0 && (
{done.map(note => ( ))}
)}
) }