<?php

namespace App\Filament\Association\Resources\ElectionResource\RelationManagers;

use App\Models\ElectionCertification;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Table;

class CertificationsRelationManager extends RelationManager
{
    protected static string $relationship = 'certifications';
    protected static ?string $title = 'Certifications';

    public function table(Table $table): Table
    {
        return $table
            ->columns([
                Tables\Columns\TextColumn::make('certifier.firstname')
                    ->label('Certified By')
                    ->formatStateUsing(fn ($record) => $record->certifier
                        ? trim($record->certifier->firstname . ' ' . $record->certifier->surname)
                        : '—'),
                Tables\Columns\TextColumn::make('action')
                    ->badge()
                    ->color(fn (string $state): string => match ($state) {
                        'certify' => 'success',
                        'contest' => 'warning',
                        'reject' => 'danger',
                        default => 'gray',
                    })
                    ->formatStateUsing(fn (string $state) => ElectionCertification::ACTIONS[$state] ?? ucfirst($state)),
                Tables\Columns\TextColumn::make('comments')
                    ->limit(50)
                    ->toggleable(),
                Tables\Columns\TextColumn::make('created_at')
                    ->dateTime('M d, Y H:i')
                    ->sortable(),
            ])
            ->defaultSort('created_at', 'desc')
            ->actions([])
            ->bulkActions([]);
    }
}
