<?php

namespace App\Filament\Pages;

use App\Filament\Pages\Concerns\HasSaveHeaderAction;
use App\Models\Footer;
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 ReglageFooter extends Page implements HasForms
{
    use HasSaveHeaderAction;
    use InteractsWithForms;

    protected static ?string $navigationIcon = 'heroicon-o-bars-3-bottom-left';

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

    protected static ?string $navigationLabel = 'Pied de page';

    protected static ?string $title = 'Pied de page';

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

    public ?array $data = [];

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

    public function form(Form $form): Form
    {
        return $form->schema([
            TextInput::make('ftr_site_url')->label('URL du site')->url(),
            Tabs::make('Contenu')->tabs([
                Tab::make('Français')->schema([
                    Textarea::make('ftr_tagline_fr')->label('Tagline')->rows(2),
                    TextInput::make('ftr_localisation_fr')->label('Localisation'),
                    TextInput::make('ftr_copyright_fr')->label('Copyright'),
                ]),
                Tab::make('English')->schema([
                    Textarea::make('ftr_tagline_en')->label('Tagline')->rows(2),
                    TextInput::make('ftr_localisation_en')->label('Location'),
                    TextInput::make('ftr_copyright_en')->label('Copyright'),
                ]),
            ])->columnSpanFull(),
        ])->statePath('data');
    }

    public function save(): void
    {
        Footer::singleton()->fill($this->form->getState())->save();
        Notification::make()->title('Pied de page enregistré')->success()->send();
    }
}
