<?php

namespace App\Filament\Resources\PaperPartResource\RelationManagers;

use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Table;
use Filament\Actions\ViewAction;

class PreQuestionCandidatesRelationManager extends RelationManager
{
    protected static string $relationship = 'candidates';

    protected static ?string $recordTitleAttribute = 'question_number';

    public function table(Table $table): Table
    {
        return $table
            ->columns([
                Tables\Columns\TextColumn::make('question_number')->label('题号')->sortable(),
                Tables\Columns\TextColumn::make('status')->label('状态')->badge(),
                Tables\Columns\TextColumn::make('ai_confidence')->label('AI 置信度')->formatStateUsing(
                    fn ($state) => $state ? number_format($state * 100, 1) . '%' : '—'
                ),
                Tables\Columns\TextColumn::make('created_at')->label('创建时间')->dateTime(),
            ])
            ->actions([
                ViewAction::make()
                    ->label('查看候选')
                    ->url(fn ($record) => route('filament.admin.resources.pre-question-candidates.index', [
                        'import_id' => $record->import_id,
                    ]))
                    ->openUrlInNewTab(),
            ])
            ->headerActions([]);
    }
}
