<?php

namespace App\Filament\Resources;

use App\Filament\Resources\StatResource\Pages;
use App\Models\Stat;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables\Actions\DeleteAction;
use Filament\Tables\Actions\EditAction;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;

class StatResource extends Resource
{
    protected static ?string $model = Stat::class;

    protected static ?string $navigationIcon = 'heroicon-o-chart-bar';

    protected static ?string $navigationGroup = 'Contenu du site';

    protected static ?string $navigationLabel = 'Statistiques';

    protected static ?string $modelLabel = 'statistique';

    protected static ?string $pluralModelLabel = 'statistiques';

    public static function form(Form $form): Form
    {
        return $form->schema([
            TextInput::make('stat_valeur')
                ->label('Valeur (ex: 20+, 1,4 Md)')
                ->required()
                ->maxLength(50),
            TextInput::make('stat_label_fr')
                ->label('Libellé (Français)')
                ->required()
                ->maxLength(255),
            TextInput::make('stat_label_en')
                ->label('Libellé (English)')
                ->required()
                ->maxLength(255),
            TextInput::make('stat_ordre')
                ->label('Ordre d\'affichage')
                ->numeric()
                ->default(0),
        ]);
    }

    public static function table(Table $table): Table
    {
        return $table
            ->defaultSort('stat_ordre')
            ->reorderable('stat_ordre')
            ->columns([
                TextColumn::make('stat_valeur')->label('Valeur'),
                TextColumn::make('stat_label_fr')->label('Libellé FR')->limit(40),
                TextColumn::make('stat_label_en')->label('Libellé EN')->limit(40),
                TextColumn::make('stat_ordre')->label('Ordre')->sortable(),
            ])
            ->actions([
                EditAction::make()->modalWidth('lg'),
                DeleteAction::make(),
            ]);
    }

    public static function getPages(): array
    {
        return [
            'index' => Pages\ListStats::route('/'),
        ];
    }
}
