<?php

declare(strict_types=1);

namespace App\Filament\Resources\Categories\Tables;

use App\Filament\Resources\Articles\ArticleResource;
use App\Filament\Support\AdminTable;
use App\Models\Category;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;

class CategoriesTable
{
    public static function configure(Table $table): Table
    {
        return $table
            ->columns([
                AdminTable::ellipsis(
                    TextColumn::make('name')
                        ->label(__('admin.fields.name'))
                        ->searchable(),
                ),
                TextColumn::make('display_order')
                    ->label(__('admin.fields.display_order'))
                    ->numeric()
                    ->sortable(),
                TextColumn::make('articles_count')
                    ->label(__('admin.fields.articles_count'))
                    ->numeric()
                    ->sortable()
                    ->url(fn (Category $record): string => ArticleResource::getUrl('index', [
                        'filters' => [
                            'category_id' => ['value' => $record->id],
                        ],
                    ])),
                AdminTable::ellipsis(
                    TextColumn::make('description')
                        ->label(__('admin.fields.description'))
                        ->toggleable(),
                ),
                TextColumn::make('created_at')
                    ->label(__('admin.fields.created_at'))
                    ->dateTime()
                    ->sortable()
                    ->toggleable(isToggledHiddenByDefault: true),
                TextColumn::make('updated_at')
                    ->label(__('admin.fields.updated_at'))
                    ->dateTime()
                    ->sortable()
                    ->toggleable(isToggledHiddenByDefault: true),
            ])
            ->filters([
                //
            ])
            ->recordActions([
                EditAction::make(),
            ])
            ->toolbarActions([
                BulkActionGroup::make([
                    DeleteBulkAction::make(),
                ]),
            ]);
    }
}
