<?php

namespace App\Filament\Resources\ProgrammeSessionResource\Pages;

use App\Filament\Resources\ProgrammeSessionResource;
use App\Models\Reglage;
use Filament\Actions\Action;
use Filament\Actions\CreateAction;
use Filament\Forms\Components\TextInput;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\ListRecords;

class ListProgrammeSessions extends ListRecords
{
    protected static string $resource = ProgrammeSessionResource::class;

    protected function getHeaderActions(): array
    {
        return [
            Action::make('lien_inscription')
                ->label('Lien du bouton « S\'inscrire »')
                ->icon('heroicon-o-link')
                ->color('gray')
                ->form([
                    TextInput::make('set_prog_lien_inscription')
                        ->label('URL du formulaire d\'inscription')
                        ->helperText('Lien utilisé par le bouton "En savoir plus & s\'inscrire" de la section Programme, en page d\'accueil.')
                        ->url()
                        ->required(),
                ])
                ->fillForm(fn (): array => [
                    'set_prog_lien_inscription' => Reglage::singleton()->set_prog_lien_inscription,
                ])
                ->action(function (array $data): void {
                    Reglage::singleton()->fill($data)->save();
                    Notification::make()->title('Lien d\'inscription enregistré')->success()->send();
                }),
            CreateAction::make()->modalWidth('2xl'),
        ];
    }
}
