<?php

namespace App\Filament\Resources\DisciplinaryReports\Tables;

use App\Enums\DisciplinarySeverity;
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\IconColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Filters\TrashedFilter;
use Filament\Tables\Table;

class DisciplinaryReportsTable
{
    public static function configure(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make('employee.full_name')
                    ->label(__('hr.fields.employee'))
                    ->searchable()
                    ->sortable(),
                TextColumn::make('report_date')
                    ->label(__('hr.fields.report_date'))
                    ->date()
                    ->sortable(),
                TextColumn::make('title')
                    ->label(__('hr.fields.title'))
                    ->searchable()
                    ->sortable(),
                TextColumn::make('severity')
                    ->label(__('hr.fields.severity'))
                    ->badge()
                    ->color(fn (DisciplinarySeverity $state): string => $state->color())
                    ->formatStateUsing(fn (DisciplinarySeverity $state): string => $state->label())
                    ->searchable()
                    ->sortable(),
                IconColumn::make('attachment_path')
                    ->label(__('hr.fields.attachment'))
                    ->boolean()
                    ->trueIcon('heroicon-o-paper-clip')
                    ->falseIcon('heroicon-o-minus'),
                TextColumn::make('creator.name')
                    ->label(__('hr.fields.created_by'))
                    ->sortable()
                    ->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('severity')
                    ->label(__('hr.fields.severity'))
                    ->options(DisciplinarySeverity::class),
                TrashedFilter::make(),
            ])
            ->recordActions([
                ViewAction::make(),
                EditAction::make(),
            ])
            ->toolbarActions([
                BulkActionGroup::make([
                    ExportExcelAction::bulk('exportSelected', \App\Exports\ReportsExport::class, 'disciplinary-reports.xlsx'),
                    DeleteBulkAction::make(),
                    ForceDeleteBulkAction::make(),
                    RestoreBulkAction::make(),
                ]),
            ]);
    }
}
