<?php

namespace App\Filament\Widgets;

use App\Models\Nota;
use Filament\Widgets\ChartWidget;

class NoteChartWidget extends ChartWidget
{
    protected static ?string $heading = 'Distribuția notelor';
    protected static ?int $sort = 2;
    protected int | string | array $columnSpan = 'half';

    protected function getData(): array
    {
        $distribution = [];
        for ($i = 1; $i <= 10; $i++) {
            $distribution[$i] = Nota::where('valoare', $i)->where('tip', '!=', 'final')->count();
        }

        return [
            'datasets' => [
                [
                    'label' => 'Număr note',
                    'data' => array_values($distribution),
                    'backgroundColor' => [
                        '#ef4444', '#ef4444', '#ef4444', '#ef4444',
                        '#f59e0b', '#f59e0b',
                        '#22c55e', '#22c55e', '#22c55e', '#22c55e',
                    ],
                    'borderWidth' => 0,
                ],
            ],
            'labels' => ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'],
        ];
    }

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