<?php

namespace App\Filament\Resources\MemberPoints\Tables;

use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Table;

class MemberPointsTable
{
    public static function configure(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make('user.name')->label('Anggota')->searchable()->sortable(),
                TextColumn::make('points')->label('Poin')->sortable()
                    ->color(fn ($state) => $state > 0 ? 'success' : 'danger'),
                TextColumn::make('reason')->label('Keterangan')->limit(50),
                TextColumn::make('source_type')->label('Sumber')->badge()
                    ->color(fn ($state) => match ($state) {
                        'activity' => 'info',
                        'post'     => 'warning',
                        default    => 'gray',
                    }),
                TextColumn::make('created_at')->label('Tanggal')->date('d M Y')->sortable(),
            ])
            ->defaultSort('created_at', 'desc')
            ->filters([
                SelectFilter::make('source_type')->label('Sumber')
                    ->options(['activity' => 'Kegiatan', 'post' => 'Artikel']),
            ])
            ->toolbarActions([BulkActionGroup::make([DeleteBulkAction::make()])]);
    }
}
