<?php

namespace App\Filament\Resources\Bonuses\Tables;

use App\Enums\BonusType;
use App\Filament\Support\ExportExcelAction;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Actions\ForceDeleteBulkAction;
use Filament\Actions\RestoreBulkAction;
use Filament\Actions\ViewAction;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Filters\TrashedFilter;
use Filament\Tables\Table;

class BonusesTable
{
    public static function configure(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make('employee.full_name')
                    ->label(__('hr.fields.employee'))
                    ->searchable()
                    ->sortable(),
                TextColumn::make('bonus_date')
                    ->label(__('hr.fields.bonus_date'))
                    ->date()
                    ->sortable(),
                TextColumn::make('bonus_type')
                    ->label(__('hr.fields.type'))
                    ->badge()
                    ->color(fn (BonusType $state): string => $state->color())
                    ->formatStateUsing(fn (BonusType $state): string => $state->label())
                    ->searchable()
                    ->sortable(),
                TextColumn::make('amount')
                    ->label(__('hr.fields.amount'))
                    ->money('TMT')
                    ->sortable(),
                TextColumn::make('reason')
                    ->label(__('hr.fields.reason'))
                    ->limit(40)
                    ->toggleable(),
                TextColumn::make('created_at')
                    ->label(__('hr.fields.created_at'))
                    ->dateTime()
                    ->sortable()
                    ->toggleable(isToggledHiddenByDefault: true),
                TextColumn::make('updated_at')
                    ->label(__('hr.fields.updated_at'))
                    ->dateTime()
                    ->sortable()
                    ->toggleable(isToggledHiddenByDefault: true),
                TextColumn::make('deleted_at')
                    ->label(__('hr.fields.deleted_at'))
                    ->dateTime()
                    ->sortable()
                    ->toggleable(isToggledHiddenByDefault: true),
            ])
            ->filters([
                SelectFilter::make('bonus_type')
                    ->label(__('hr.fields.type'))
                    ->options(BonusType::class),
                TrashedFilter::make(),
            ])
            ->recordActions([
                ViewAction::make(),
                EditAction::make(),
            ])
            ->toolbarActions([
                BulkActionGroup::make([
                    ExportExcelAction::bulk('exportSelected', \App\Exports\BonusesExport::class, 'bonuses.xlsx'),
                    DeleteBulkAction::make(),
                    ForceDeleteBulkAction::make(),
                    RestoreBulkAction::make(),
                ]),
            ]);
    }
}
