<?php

namespace App\Filament\Resources\DeliveryCalendarOverrides\Tables;

use App\Enums\OverrideScope;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Actions\ForceDeleteBulkAction;
use Filament\Actions\RestoreBulkAction;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Filters\TrashedFilter;
use Filament\Tables\Table;

class DeliveryCalendarOverridesTable
{
    public static function configure(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make('supplier.name')
                    ->label('Beszállító')
                    ->searchable()
                    ->sortable(),
                TextColumn::make('override_scope')
                    ->label('Szint')
                    ->badge()
                    ->formatStateUsing(fn(OverrideScope $state) => $state->label())
                    ->color(fn(OverrideScope $state) => $state->color())
                    ->sortable(),
                TextColumn::make('deliverySchedule.name')
                    ->label('Szállítási sablon')
                    ->placeholder('—')
                    ->toggleable(),
                TextColumn::make('profitCenter.name')
                    ->label('Profitcenter')
                    ->placeholder('—')
                    ->toggleable(),
                TextColumn::make('date')
                    ->label('Dátum')
                    ->date('Y-m-d')
                    ->sortable(),
                IconColumn::make('is_delivery_day')
                    ->boolean()
                    ->label('Szállítási nap'),
                TextColumn::make('description')
                    ->label('Megjegyzés')
                    ->limit(30)
                    ->toggleable(isToggledHiddenByDefault: true),
            ])
            ->filters([
                SelectFilter::make('override_scope')
                    ->label('Felülbírálás szintje')
                    ->options(collect(OverrideScope::cases())->mapWithKeys(
                        fn(OverrideScope $scope) => [$scope->value => $scope->label()]
                    )),
                TrashedFilter::make(),
            ])
            ->recordActions([
                EditAction::make(),
            ])
            ->toolbarActions([
                BulkActionGroup::make([
                    DeleteBulkAction::make(),
                    ForceDeleteBulkAction::make(),
                    RestoreBulkAction::make(),
                ]),
            ]);
    }
}
