<?php

namespace App\Filament\Resources\WorkoutSessions\Tables;

use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Table;
use Functional\Tracking\Enums\WorkoutSessionStatus;

/**
 * Table des séances : utilisateur, statut, début, volume total.
 */
class WorkoutSessionsTable
{
    public static function configure(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make('user.name')
                    ->label('Utilisateur')
                    ->searchable()
                    ->sortable(),
                TextColumn::make('status')
                    ->label('Statut')
                    ->badge()
                    ->color(fn (WorkoutSessionStatus $state): string => match ($state) {
                        WorkoutSessionStatus::Active => 'warning',
                        WorkoutSessionStatus::Completed => 'success',
                        WorkoutSessionStatus::Abandoned => 'danger',
                    }),
                TextColumn::make('started_at')
                    ->label('Débutée le')
                    ->dateTime()
                    ->sortable(),
                TextColumn::make('total_volume')
                    ->label('Volume total')
                    ->numeric()
                    ->sortable(),
            ])
            ->filters([
                SelectFilter::make('status')
                    ->label('Statut')
                    ->options(WorkoutSessionStatus::class),
            ])
            ->recordActions([
                EditAction::make(),
            ])
            ->toolbarActions([
                BulkActionGroup::make([
                    DeleteBulkAction::make(),
                ]),
            ])
            ->defaultSort('started_at', 'desc');
    }
}
