<?php

declare(strict_types=1);

namespace App\Filament\Resources\Breeds\Tables;

use App\Filament\Support\SelectOptionLabels;

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

class BreedsTable
{
    public static function configure(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make('name')
                    ->label('نام نژاد')
                    ->searchable()
                    ->sortable(),
                
                TextColumn::make('en_name')
                    ->label('نام انگلیسی')
                    ->searchable()
                    ->sortable(),
                
                TextColumn::make('category.title')
                    ->label('دسته')
                    ->searchable()
                    ->sortable(),
                
                TextColumn::make('status')
                    ->label('وضعیت')
                    ->badge()
                    ->color(fn (string $state): string => match ($state) {
                        'active' => 'success',
                        'inactive' => 'danger',
                        default => 'gray',
                    })
                    ->formatStateUsing(fn (string $state): string => match ($state) {
                        'active' => 'فعال',
                        'inactive' => 'غیرفعال',
                        default => $state,
                    }),
                
                TextColumn::make('createdBy.name')
                    ->label('ایجادکننده')
                    ->hidden()
                    ->searchable()
                    ->sortable(),
                
                TextColumn::make('created_at')
                    ->label('تاریخ ایجاد')
                    ->jalaliDateTime('Y/m/d H:i')
                    ->sortable(),
            ])
            ->filters([
                TrashedFilter::make(),
                SelectFilter::make('status')
                    ->label('وضعیت')
                    ->options([
                        'active' => 'فعال',
                        'inactive' => 'غیرفعال',
                    ]),
                SelectFilter::make('category_id')
                    ->label('دسته')
                    ->relationship('category', 'title')
                    ->getOptionLabelFromRecordUsing(fn ($record) => SelectOptionLabels::category($record))
                    ->searchable()
                    ->preload(),
            ])
            ->recordActions([
                EditAction::make(),
            ])
            ->toolbarActions([
                BulkActionGroup::make([
                    DeleteBulkAction::make(),
                    ForceDeleteBulkAction::make(),
                    RestoreBulkAction::make(),
                ]),
            ]);
    }
}

