<?php

namespace App\Filament\Resources\Pireps\RelationManagers;

use App\Models\PirepFare;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Schemas\Schema;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;

class FaresRelationManager extends RelationManager
{
    protected static string $relationship = 'fares';

    #[\Override]
    public function form(Schema $schema): Schema
    {
        return $schema
            ->components([
                //
            ]);
    }

    public function table(Table $table): Table
    {
        return $table
            ->recordTitleAttribute('code')
            ->paginated(false)
            ->modifyQueryUsing(fn ($query) => $query->with(['fare', 'pirep']))
            ->columns([
                TextColumn::make('fare')
                    ->label(trans_choice('pireps.fare', 1))
                    ->formatStateUsing(fn (PirepFare $record): string => $record->name.' ('.$record->code.')'),

                TextColumn::make('count')
                    ->label(__('pireps.count'))
                    ->extraAttributes(['class' => 'fi-pirep-money-mono']),

                TextColumn::make('price')
                    ->label(__('common.price'))
                    ->money(setting('units.currency'))
                    ->extraAttributes(['class' => 'fi-pirep-money-mono']),

                TextColumn::make('capacity')
                    ->label(__('common.capacity')),
            ])
            ->filters([
                //
            ])
            ->headerActions([
                //
            ])
            ->recordActions([
                //
            ])
            ->toolbarActions([
                //
            ]);
    }

    #[\Override]
    protected static function getModelLabel(): string
    {
        return trans_choice( 'pireps.fare', 1);
    }

    #[\Override]
    public static function getTitle(Model $ownerRecord, string $pageClass): string
    {
        return trans_choice('pireps.fare', 2);
    }
}
