'use client'; export const dynamic = 'force-dynamic'; import React, { useState, useEffect } from 'react'; import { Card } from 'primereact/card'; import { Chart } from 'primereact/chart'; import { ProgressBar } from 'primereact/progressbar'; import notificationService, { NotificationStats } from '../../../../services/notificationService'; const NotificationsStatistiquesPage = () => { const [stats, setStats] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { loadStats(); }, []); const loadStats = async () => { try { setLoading(true); const data = await notificationService.getNotificationStats(); setStats(data); } catch (error) { console.error('Erreur lors du chargement des statistiques:', error); } finally { setLoading(false); } }; const chartData = { labels: ['Info', 'Avertissement', 'Succès', 'Erreur'], datasets: [ { data: stats ? [ stats.parType.info || 0, stats.parType.warning || 0, stats.parType.success || 0, stats.parType.error || 0 ] : [0, 0, 0, 0], backgroundColor: [ '#3B82F6', '#F59E0B', '#10B981', '#EF4444' ], hoverBackgroundColor: [ '#2563EB', '#D97706', '#059669', '#DC2626' ] } ] }; const chartOptions = { plugins: { legend: { labels: { usePointStyle: true } } } }; const tendanceChartData = { labels: stats?.tendance.map(t => t.periode) || [], datasets: [ { label: 'Notifications', data: stats?.tendance.map(t => t.nombre) || [], fill: false, borderColor: '#3B82F6', tension: 0.4 } ] }; const tendanceChartOptions = { maintainAspectRatio: false, aspectRatio: 0.6, plugins: { legend: { labels: { color: '#495057' } } }, scales: { x: { ticks: { color: '#495057' }, grid: { color: '#ebedef' } }, y: { ticks: { color: '#495057' }, grid: { color: '#ebedef' } } } }; if (loading) { return (

Chargement des statistiques...

); } if (!stats) { return (

Impossible de charger les statistiques

); } const pourcentageLues = stats.total > 0 ? Math.round(((stats.total - stats.nonLues) / stats.total) * 100) : 0; return (

Statistiques des Notifications

{/* Cartes de statistiques */}
Total
{stats.total}
Non lues
{stats.nonLues}
Lues
{stats.total - stats.nonLues}
Taux de lecture
{pourcentageLues}%
{/* Graphique par type */}
{/* Graphique de tendance */}
{/* Détails par type */}
Info
0 ? (stats.parType.info / stats.total) * 100 : 0} showValue={false} className="flex-1 mr-2" color="#3B82F6" /> {stats.parType.info}
Avertissement
0 ? (stats.parType.warning / stats.total) * 100 : 0} showValue={false} className="flex-1 mr-2" color="#F59E0B" /> {stats.parType.warning}
Succès
0 ? (stats.parType.success / stats.total) * 100 : 0} showValue={false} className="flex-1 mr-2" color="#10B981" /> {stats.parType.success}
Erreur
0 ? (stats.parType.error / stats.total) * 100 : 0} showValue={false} className="flex-1 mr-2" color="#EF4444" /> {stats.parType.error}
); }; export default NotificationsStatistiquesPage;