<?php

namespace App\Filament\Resources;

use App\Filament\Resources\PageLegaleResource\Pages;
use App\Models\PageLegale;
use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\Tabs;
use Filament\Forms\Components\Tabs\Tab;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables\Actions\EditAction;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;

class PageLegaleResource extends Resource
{
    protected static ?string $model = PageLegale::class;

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

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

    protected static ?string $navigationLabel = 'Pages légales';

    protected static ?string $modelLabel = 'page légale';

    public static function form(Form $form): Form
    {
        return $form->schema([
            Tabs::make('Traductions')->tabs([
                Tab::make('Français')->schema([
                    TextInput::make('pgl_titre_fr')->label('Titre')->required()->maxLength(255),
                    RichEditor::make('pgl_contenu_fr')
                        ->label('Contenu')
                        ->toolbarButtons([
                            'blockquote',
                            'bold',
                            'bulletList',
                            'h1',
                            'h2',
                            'h3',
                            'italic',
                            'link',
                            'orderedList',
                            'redo',
                            'strike',
                            'underline',
                            'undo',
                        ])
                        ->required()
                        ->columnSpanFull(),
                ]),
                Tab::make('English')->schema([
                    TextInput::make('pgl_titre_en')->label('Title')->required()->maxLength(255),
                    RichEditor::make('pgl_contenu_en')
                        ->label('Content')
                        ->toolbarButtons([
                            'blockquote',
                            'bold',
                            'bulletList',
                            'h1',
                            'h2',
                            'h3',
                            'italic',
                            'link',
                            'orderedList',
                            'redo',
                            'strike',
                            'underline',
                            'undo',
                        ])
                        ->required()
                        ->columnSpanFull(),
                ]),
            ])->columnSpanFull(),
        ]);
    }

    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make('pgl_titre_fr')->label('Titre (FR)'),
                TextColumn::make('pgl_slug')->label('Identifiant'),
            ])
            ->actions([
                EditAction::make()->modalWidth('4xl'),
            ]);
    }

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

    public static function canCreate(): bool
    {
        return false;
    }

    public static function canDelete(Model $record): bool
    {
        return false;
    }
}
