<?php

namespace App\Filament\Resources;

use App\Filament\Resources\TerritoireResource\Pages;
use App\Models\Territoire;
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 TerritoireResource extends Resource
{
    protected static ?string $model = Territoire::class;

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

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

    protected static ?string $navigationLabel = 'Océan Indien (Zone)';

    protected static ?string $modelLabel = 'territoire';

    public static function form(Form $form): Form
    {
        return $form->schema([
            TextInput::make('terr_slug')->label('Identifiant (slug)')->required()->maxLength(50),
            TextInput::make('terr_ordre')->label('Ordre')->numeric()->default(0),
            Tabs::make('Traductions')->tabs([
                Tab::make('Français')->schema([
                    TextInput::make('terr_nom_fr')->label('Nom')->required()->maxLength(100),
                    TextInput::make('terr_tag_fr')->label('Tag')->required()->maxLength(150),
                    Textarea::make('terr_desc_fr')->label('Description')->required()->rows(3),
                ]),
                Tab::make('English')->schema([
                    TextInput::make('terr_nom_en')->label('Name')->required()->maxLength(100),
                    TextInput::make('terr_tag_en')->label('Tag')->required()->maxLength(150),
                    Textarea::make('terr_desc_en')->label('Description')->required()->rows(3),
                ]),
            ])->columnSpanFull(),
        ]);
    }

    public static function table(Table $table): Table
    {
        return $table
            ->defaultSort('terr_ordre')
            ->reorderable('terr_ordre')
            ->columns([
                TextColumn::make('terr_nom_fr')->label('Nom (FR)'),
                TextColumn::make('terr_tag_fr')->label('Tag (FR)')->limit(40),
                TextColumn::make('terr_ordre')->label('Ordre')->sortable(),
            ])
            ->actions([
                EditAction::make()->modalWidth('2xl'),
                DeleteAction::make(),
            ]);
    }

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