<?php

declare(strict_types=1);

namespace App\Filament\Resources\Users\Tables;

use App\Filament\Support\AdminTable;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;

class UsersTable
{
    public static function configure(Table $table): Table
    {
        return $table
            ->columns([
                AdminTable::stickyStart(
                    TextColumn::make('id')
                        ->label(__('admin.fields.id'))
                        ->sortable(),
                ),
                TextColumn::make('username')
                    ->label(__('admin.fields.username'))
                    ->searchable()
                    ->sortable(),
                AdminTable::ellipsis(
                    TextColumn::make('name')
                        ->label(__('admin.fields.display_name'))
                        ->searchable(),
                ),
                AdminTable::ellipsis(
                    TextColumn::make('email')
                        ->label(__('admin.fields.email'))
                        ->searchable(),
                ),
                TextColumn::make('roles.name')
                    ->badge()
                    ->label(__('admin.fields.roles')),
                TextColumn::make('login_at')
                    ->label(__('admin.fields.login_at'))
                    ->dateTime()
                    ->sortable(),
                TextColumn::make('created_at')
                    ->label(__('admin.fields.created_at'))
                    ->dateTime()
                    ->sortable()
                    ->toggleable(isToggledHiddenByDefault: true),
            ])
            ->recordActions([
                EditAction::make(),
            ])
            ->toolbarActions([
                BulkActionGroup::make([
                    DeleteBulkAction::make(),
                ]),
            ]);
    }
}
