<?php

namespace App\Filament\Resources;

use App\Filament\Resources\TemoignageResource\Pages;
use App\Models\Temoignage;
use Filament\Forms\Components\Tabs;
use Filament\Forms\Components\Tabs\Tab;
use Filament\Forms\Components\Textarea;
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 TemoignageResource extends Resource
{
    protected static ?string $model = Temoignage::class;

    protected static ?string $navigationIcon = 'heroicon-o-chat-bubble-left-right';

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

    protected static ?string $navigationLabel = 'Témoignages';

    protected static ?string $modelLabel = 'témoignage';

    public static function form(Form $form): Form
    {
        return $form->schema([
            TextInput::make('tst_auteur')->label('Nom de l\'auteur')->required()->maxLength(150),
            TextInput::make('tst_initiales')->label('Initiales (avatar)')->required()->maxLength(5),
            TextInput::make('tst_ordre')->label('Ordre')->numeric()->default(0),
            Tabs::make('Traductions')->tabs([
                Tab::make('Français')->schema([
                    Textarea::make('tst_citation_fr')->label('Citation')->required()->rows(3),
                    TextInput::make('tst_role_fr')->label('Rôle / fonction')->required()->maxLength(150),
                ]),
                Tab::make('English')->schema([
                    Textarea::make('tst_citation_en')->label('Quote')->required()->rows(3),
                    TextInput::make('tst_role_en')->label('Role')->required()->maxLength(150),
                ]),
            ])->columnSpanFull(),
        ]);
    }

    public static function table(Table $table): Table
    {
        return $table
            ->defaultSort('tst_ordre')
            ->reorderable('tst_ordre')
            ->columns([
                TextColumn::make('tst_auteur')->label('Auteur'),
                TextColumn::make('tst_role_fr')->label('Rôle (FR)'),
                TextColumn::make('tst_citation_fr')->label('Citation (FR)')->limit(50),
            ])
            ->actions([
                EditAction::make()->modalWidth('2xl'),
                DeleteAction::make(),
            ]);
    }

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