<?php

namespace App\Filament\Resources\SourcePaperResource\RelationManagers;

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

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('sequence')->label('序')->sortable(),
                Tables\Columns\TextColumn::make('index')->label('题号')->sortable(),
                Tables\Columns\TextColumn::make('part.title')->label('区块')->toggleable(),
                Tables\Columns\TextColumn::make('status')->label('状态')->badge(),
                Tables\Columns\TextColumn::make('ai_confidence')
                    ->label('AI 置信度')
                    ->formatStateUsing(fn ($state) => $state ? number_format($state * 100, 1) . '%' : '—')
                    ->badge(),
                Tables\Columns\TextColumn::make('stem')
                    ->label('题干预览')
                    ->limit(60)
                    ->wrap(),
            ])
            ->actions([])
            ->headerActions([]);
    }
}
