<?php

namespace App\Filament\Resources\Trainings\RelationManagers;

use App\Filament\Resources\TrainingFeedbacks\Schemas\TrainingFeedbackForm;
use Filament\Actions\EditAction;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Schemas\Schema;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;

class FeedbackSubmissionsRelationManager extends RelationManager
{
    protected static string $relationship = 'feedbacks';

    protected static ?string $title = 'Feedback submissions';

    public function form(Schema $schema): Schema
    {
        return TrainingFeedbackForm::configure($schema);
    }

    public function table(Table $table): Table
    {
        return $table
            ->defaultSort('created_at', 'desc')
            ->emptyStateHeading('No feedback submissions yet')
            ->emptyStateDescription('Share this training\'s unique feedback link. Responses will appear here automatically.')
            ->columns([
                TextColumn::make('name')->searchable()->placeholder('Anonymous'),
                TextColumn::make('email')->searchable()->placeholder('Not provided'),
                TextColumn::make('overall_experience')->label('Overall')->suffix(' / 5')->badge()->sortable(),
                TextColumn::make('content_satisfaction')->label('Content')->suffix(' / 5')->sortable(),
                TextColumn::make('trainer_expertise')->label('Trainer')->suffix(' / 5')->sortable(),
                TextColumn::make('created_at')->label('Submitted')->dateTime('j M Y, g:i a')->sortable(),
            ])
            ->recordActions([
                EditAction::make()->label('Review'),
            ]);
    }
}
