'use client'; import React, { useState } from 'react'; import { Trash2, Edit2, ClipboardList, ChevronDown, ChevronUp } from 'lucide-react'; import Button from '@/components/Form/Button'; import Popup from '@/components/Popup'; import { useNotification } from '@/context/NotificationContext'; export default function EvaluationList({ evaluations, onDelete, onEdit, onGradeStudents, }) { const [expandedId, setExpandedId] = useState(null); const [deletePopupVisible, setDeletePopupVisible] = useState(false); const [evaluationToDelete, setEvaluationToDelete] = useState(null); const { showNotification } = useNotification(); const handleDeleteClick = (evaluation) => { setEvaluationToDelete(evaluation); setDeletePopupVisible(true); }; const handleConfirmDelete = () => { if (evaluationToDelete && onDelete) { onDelete(evaluationToDelete.id) .then(() => { showNotification('Évaluation supprimée avec succès', 'success', 'Succès'); setDeletePopupVisible(false); setEvaluationToDelete(null); }) .catch((error) => { showNotification('Erreur lors de la suppression', 'error', 'Erreur'); }); } }; // Grouper les évaluations par matière const groupedBySpeciality = evaluations.reduce((acc, ev) => { const key = ev.speciality_name || 'Sans matière'; if (!acc[key]) { acc[key] = { name: key, color: ev.speciality_color || '#6B7280', evaluations: [], }; } acc[key].evaluations.push(ev); return acc; }, {}); if (evaluations.length === 0) { return (
Aucune évaluation créée pour cette période
); } return (
{Object.values(groupedBySpeciality).map((group) => (
setExpandedId(expandedId === group.name ? null : group.name) } >
{group.name} ({group.evaluations.length} évaluation {group.evaluations.length > 1 ? 's' : ''})
{expandedId === group.name ? ( ) : ( )}
{expandedId === group.name && (
{group.evaluations.map((evaluation) => (
{evaluation.name}
{evaluation.date && ( {new Date(evaluation.date).toLocaleDateString('fr-FR')} )} Note max: {evaluation.max_score} Coef: {evaluation.coefficient}
))}
)}
))} { setDeletePopupVisible(false); setEvaluationToDelete(null); }} />
); }