<?php

namespace App\Filament\Resources\Corridors\Tables;

use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\TernaryFilter;
use Filament\Tables\Table;

class CorridorsTable
{
    public static function configure(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make('fromCity.name_en')
                    ->label('From')
                    ->searchable()
                    ->sortable(),
                TextColumn::make('toCity.name_en')
                    ->label('To')
                    ->searchable()
                    ->sortable(),
                TextColumn::make('distance_km')
                    ->label('Distance')
                    ->suffix(' km')
                    ->numeric()
                    ->sortable(),
                TextColumn::make('min_price_tzs')
                    ->label('Min Price')
                    ->money('TZS', locale: 'en')
                    ->sortable(),
                IconColumn::make('is_active')
                    ->label('Active')
                    ->boolean(),
                TextColumn::make('created_at')
                    ->dateTime()
                    ->sortable()
                    ->toggleable(isToggledHiddenByDefault: true),
            ])
            ->defaultSort('fromCity.name_en')
            ->filters([
                TernaryFilter::make('is_active')->label('Active corridors'),
            ])
            ->recordActions([
                EditAction::make(),
            ])
            ->toolbarActions([
                BulkActionGroup::make([
                    DeleteBulkAction::make(),
                ]),
            ]);
    }
}
