<?php

namespace App\Filament\Pages;

use App\Filament\Pages\Concerns\HasSaveHeaderAction;
use App\Models\About;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Tabs;
use Filament\Forms\Components\Tabs\Tab;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
use Filament\Notifications\Notification;
use Filament\Pages\Page;

/** @property Form $form */
class ReglageAbout extends Page implements HasForms
{
    use HasSaveHeaderAction;
    use InteractsWithForms;

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

    protected static ?string $navigationGroup = 'Réglages du site';

    protected static ?string $navigationLabel = 'À propos';

    protected static ?string $title = 'Section « À propos »';

    protected static string $view = 'filament.pages.simple-form-page';

    public ?array $data = [];

    public function mount(): void
    {
        $this->form->fill(About::singleton()->toArray());
    }

    public function form(Form $form): Form
    {
        return $form->schema([
            FileUpload::make('abt_portrait')->label('Photo portrait')->image()->directory('assets')->visibility('public'),
            TextInput::make('abt_linkedin_url')->label('URL LinkedIn')->url(),
            Tabs::make('Contenu')->tabs([
                Tab::make('Français')->schema([
                    TextInput::make('abt_eyebrow_fr')->label('Sur-titre'),
                    TextInput::make('abt_title_fr')->label('Titre')
                        ->helperText("Entourez une partie du texte de doubles crochets [[ ... ]] pour l'afficher en dégradé doré."),
                    Textarea::make('abt_bio1_fr')->label('Bio — paragraphe 1')->rows(3),
                    Textarea::make('abt_bio2_fr')->label('Bio — paragraphe 2')->rows(3),
                    Textarea::make('abt_bio3_fr')->label('Bio — paragraphe 3')->rows(3),
                    Textarea::make('abt_bio4_fr')->label('Bio — paragraphe 4')->rows(3),
                ]),
                Tab::make('English')->schema([
                    TextInput::make('abt_eyebrow_en')->label('Eyebrow'),
                    TextInput::make('abt_title_en')->label('Title')
                        ->helperText('Wrap part of the text in double square brackets [[ ... ]] to display it in the gold gradient style.'),
                    Textarea::make('abt_bio1_en')->label('Bio — paragraph 1')->rows(3),
                    Textarea::make('abt_bio2_en')->label('Bio — paragraph 2')->rows(3),
                    Textarea::make('abt_bio3_en')->label('Bio — paragraph 3')->rows(3),
                    Textarea::make('abt_bio4_en')->label('Bio — paragraph 4')->rows(3),
                ]),
            ])->columnSpanFull(),
        ])->statePath('data');
    }

    public function save(): void
    {
        About::singleton()->fill($this->form->getState())->save();
        Notification::make()->title('Section « À propos » enregistrée')->success()->send();
    }
}
