<?php

namespace App\Filament\Resources\Users\Tables;

use App\Models\Division;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Table;
use STS\FilamentImpersonate\Actions\Impersonate;

class UsersTable
{
    public static function configure(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make('name')->searchable()->sortable(),
                TextColumn::make('email')->searchable(),
                TextColumn::make('phone')->label('Telepon'),
                TextColumn::make('division.name')->label('Divisi')->sortable(),
                TextColumn::make('status')->badge()
                    ->color(fn ($state) => $state === 'aktif' ? 'success' : 'danger'),
                TextColumn::make('roles.name')->label('Role')->badge(),
            ])
            ->filters([
                SelectFilter::make('status')
                    ->options(['aktif' => 'Aktif', 'nonaktif' => 'Nonaktif']),
                SelectFilter::make('division_id')->label('Divisi')
                    ->options(Division::pluck('name', 'id')),
            ])
            ->recordActions([EditAction::make(), Impersonate::make()])
            ->toolbarActions([BulkActionGroup::make([DeleteBulkAction::make()])]);
    }
}
