'use client'; export const dynamic = 'force-dynamic'; import React, { useState, useEffect } from 'react'; import { Card } from 'primereact/card'; import { Chart } from 'primereact/chart'; import { Button } from 'primereact/button'; import { Toolbar } from 'primereact/toolbar'; import { DataTable } from 'primereact/datatable'; import { Column } from 'primereact/column'; import { Tag } from 'primereact/tag'; import { useRouter } from 'next/navigation'; import { apiClient } from '../../../../services/api-client'; interface StatistiquesEmployes { totalEmployes: number; employesActifs: number; employesInactifs: number; employesEnConge: number; employesEnFormation: number; repartitionParMetier: { [key: string]: number }; repartitionParExperience: { [key: string]: number }; repartitionParEquipe: { [key: string]: number }; employesSansCertification: number; employesAvecCertifications: number; moyenneAgeEmployes: number; ancienneteMoyenne: number; tauxDisponibilite: number; topCompetences: Array<{ competence: string; nombre: number }>; topCertifications: Array<{ certification: string; nombre: number }>; } const StatistiquesEmployesPage = () => { const [stats, setStats] = useState(null); const [loading, setLoading] = useState(true); const [chartOptions] = useState({ responsive: true, maintainAspectRatio: false, plugins: { legend: { position: 'bottom' } } }); const router = useRouter(); useEffect(() => { loadStatistiques(); }, []); const loadStatistiques = async () => { try { setLoading(true); console.log('🔄 Chargement des statistiques employés...'); const response = await apiClient.get('/api/employes/statistiques'); console.log('✅ Statistiques employés chargées:', response.data); setStats(response.data); } catch (error) { console.error('❌ Erreur lors du chargement des statistiques:', error); } finally { setLoading(false); } }; const getStatutChartData = () => { if (!stats) return {}; return { labels: ['Actifs', 'Inactifs', 'En congé', 'En formation'], datasets: [{ data: [ stats.employesActifs, stats.employesInactifs, stats.employesEnConge, stats.employesEnFormation ], backgroundColor: [ '#4CAF50', '#F44336', '#FF9800', '#2196F3' ], borderWidth: 2 }] }; }; const getMetierChartData = () => { if (!stats) return {}; return { labels: Object.keys(stats.repartitionParMetier), datasets: [{ data: Object.values(stats.repartitionParMetier), backgroundColor: [ '#FF6384', '#36A2EB', '#FFCE56', '#4BC0C0', '#9966FF', '#FF9F40', '#FF6384', '#C9CBCF' ], borderWidth: 2 }] }; }; const getExperienceChartData = () => { if (!stats) return {}; return { labels: Object.keys(stats.repartitionParExperience), datasets: [{ label: 'Nombre d\'employés', data: Object.values(stats.repartitionParExperience), backgroundColor: '#36A2EB', borderColor: '#36A2EB', borderWidth: 1 }] }; }; const leftToolbarTemplate = () => { return (
); }; const rightToolbarTemplate = () => { return (