<?php

namespace App\Filament\Resources\TrainingFeedbacks\Tables;

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

class TrainingFeedbacksTable
{
    public static function configure(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make('name')
                    ->searchable()
                    ->placeholder('Anonymous'),
                TextColumn::make('email')
                    ->searchable()
                    ->placeholder('N/A'),
                TextColumn::make('organization')
                    ->searchable()
                    ->placeholder('N/A'),
                TextColumn::make('event_name')
                    ->label('Event')
                    ->searchable()
                    ->placeholder('N/A'),
                TextColumn::make('training_date')
                    ->date()
                    ->sortable()
                    ->toggleable(),
                TextColumn::make('facilitator')
                    ->searchable()
                    ->toggleable(isToggledHiddenByDefault: true),
                TextColumn::make('audience_segment')
                    ->label('Audience')
                    ->toggleable(isToggledHiddenByDefault: true),
                TextColumn::make('overall_experience')
                    ->label('Overall Experience (1-5)')
                    ->sortable(),
                TextColumn::make('content_satisfaction')
                    ->label('Content Sat (1-5)')
                    ->sortable()
                    ->toggleable(isToggledHiddenByDefault: true),
                TextColumn::make('trainer_expertise')
                    ->label('Trainer Exp (1-5)')
                    ->sortable()
                    ->toggleable(isToggledHiddenByDefault: true),
                TextColumn::make('created_at')
                    ->label('Submitted At')
                    ->dateTime()
                    ->sortable(),
            ])
            ->filters([
                SelectFilter::make('organization')
                    ->options(fn () => \App\Models\TrainingFeedback::query()
                        ->whereNotNull('organization')
                        ->orderBy('organization')
                        ->pluck('organization', 'organization')
                        ->all()),
                SelectFilter::make('event_name')
                    ->label('Event')
                    ->options(fn () => \App\Models\TrainingFeedback::query()
                        ->whereNotNull('event_name')
                        ->orderBy('event_name')
                        ->pluck('event_name', 'event_name')
                        ->all()),
                SelectFilter::make('audience_segment')
                    ->label('Audience')
                    ->options(fn () => \App\Models\TrainingFeedback::query()
                        ->whereNotNull('audience_segment')
                        ->orderBy('audience_segment')
                        ->pluck('audience_segment', 'audience_segment')
                        ->all()),
            ])
            ->recordActions([
                EditAction::make(),
            ])
            ->toolbarActions([
                BulkActionGroup::make([
                    DeleteBulkAction::make(),
                ]),
            ]);
    }
}
