<?php

namespace App\Filament\Widgets;

use App\Models\Discipline;
use App\Models\Professeur;
use Filament\Widgets\ChartWidget;

class AcademicProgress extends ChartWidget
{
    protected ?string $heading = 'Progression Pédagogique par Discipline';

    protected function getData(): array
    {
        $disciplines = Discipline::all();
        
        return [
            'datasets' => [
                [
                    'label' => 'Professeurs',
                    'data' => $disciplines->map(function ($discipline) {
                        return Professeur::where('discipline_origine', $discipline->id)->count();
                    })->toArray(),
                    'backgroundColor' => 'rgba(59, 130, 246, 0.5)',
                    'borderColor' => 'rgb(59, 130, 246)',
                ],
            ],
            'labels' => $disciplines->pluck('libellefr')->toArray(),
        ];
    }

    protected function getType(): string
    {
        return 'bar';
    }
}
