<?php

namespace App\Filament\Resources\SerpChecks\Tables;

use Filament\Actions\ViewAction;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Table;

class SerpChecksTable
{
    public static function configure(Table $table): Table
    {
        return $table->modifyQueryUsing(fn ($query) => $query->with('keyword.project.user'))
            ->columns([
                TextColumn::make('ulid')->label('ULID')->searchable(),
                TextColumn::make('phrase')->label(__('admin.keyword'))->searchable(),
                TextColumn::make('keyword.project.name')->label(__('admin.project'))->searchable(),
                TextColumn::make('keyword.project.domain')->label(__('admin.domain'))->searchable(),
                TextColumn::make('keyword.project.user.email')->label(__('admin.customer'))->searchable(),
                TextColumn::make('provider')->label(__('admin.provider'))->placeholder('—'),
                TextColumn::make('status')->label(__('admin.status'))->badge()->formatStateUsing(fn ($state) => $state->label()),
                TextColumn::make('result_count')->label(__('admin.result_count')),
                TextColumn::make('created_at')->label(__('admin.created_at'))->dateTime('d.m.Y H:i')->sortable(),
            ])
            ->filters([
                SelectFilter::make('status')->label(__('admin.status'))->options([
                    'pending' => __('states.pending'), 'running' => __('states.running'),
                    'completed' => __('states.completed'), 'failed' => __('states.failed'),
                ]),
                SelectFilter::make('provider')->label(__('admin.provider')),
                SelectFilter::make('search_engine')->label(__('admin.search_engine'))->options(['google' => 'Google', 'bing' => 'Bing']),
            ])->recordActions([ViewAction::make()])->toolbarActions([]);
    }
}
