<?php

namespace App\Filament\Widgets;

use Filament\Widgets\StatsOverviewWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;
use Functional\Exercises\Models\Exercise;
use Functional\Streaks\Models\Streak;
use Functional\Tracking\Models\WorkoutSession;
use Functional\Users\Models\User;
use Illuminate\Support\Carbon;

/**
 * Vue d'ensemble du dashboard : chiffres clés de StreakFit.
 * Nb d'utilisateurs, séances (total + cette semaine), plus long streak en cours, catalogue d'exos.
 */
class StreakFitStatsOverview extends StatsOverviewWidget
{
    protected static ?int $sort = 1;

    protected function getStats(): array
    {
        $sessionsThisWeek = WorkoutSession::query()
            ->where('started_at', '>=', Carbon::now()->startOfWeek())
            ->count();

        return [
            Stat::make('Utilisateurs', (string) User::query()->count())
                ->description('Comptes inscrits')
                ->descriptionIcon('heroicon-m-users')
                ->color('primary'),

            Stat::make('Séances', (string) WorkoutSession::query()->count())
                ->description($sessionsThisWeek.' cette semaine')
                ->descriptionIcon('heroicon-m-fire')
                ->color('warning'),

            Stat::make('Meilleur streak en cours', (string) (Streak::query()->max('current_count') ?? 0))
                ->description('Jours consécutifs')
                ->descriptionIcon('heroicon-m-bolt')
                ->color('success'),

            Stat::make('Exercices', (string) Exercise::query()->count())
                ->description('Catalogue disponible')
                ->descriptionIcon('heroicon-m-rectangle-stack')
                ->color('primary'),
        ];
    }
}
