<?php

namespace App\Filament\Clusters\VisaMasterPayments\Resources\VisaMasterPaymentOrders\Tables;

use App\Modules\OrderStatus\Repositories\OrderStatusRepository;
use App\Modules\Region\Repositories\RegionRepository;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Actions\ForceDeleteBulkAction;
use Filament\Actions\RestoreBulkAction;
use Filament\Actions\ViewAction;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\TrashedFilter;
use Filament\Tables\Table;
use Illuminate\Support\Str;

class VisaMasterPaymentOrdersTable
{
    public static function configure(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make('id')
                    ->label(__('ID'))
                    ->sortable(),

                TextColumn::make('type')
                    ->label(__('Type'))
                    ->formatStateUsing(fn (string $state) => Str::upper($state)),

                TextColumn::make('status')
                    ->label(__('Status'))
                    ->color(OrderStatusRepository::statusColorMatching())
                    ->formatStateUsing(fn (string $state) => OrderStatusRepository::statusFormatted($state))
                    ->badge(),

                TextColumn::make('created_at')
                    ->label(__('Created At'))
                    ->dateTime()
                    ->sortable(),

                TextColumn::make('region')
                    ->label(__('Region'))
                    ->formatStateUsing(fn (string $state): string => RegionRepository::label($state))
                    ->searchable(),

                TextColumn::make('branch.name')
                    ->label(__('Branch'))
                    ->searchable(),

                TextColumn::make('sender_full_name')
                    ->label(__('Full Name'))
                    ->searchable(),

                TextColumn::make('phone')
                    ->label(__('Phone'))
                    ->searchable(),

                IconColumn::make('paid')
                    ->label(sprintf('%s (%s)', __('Paid'), __('This month')))
                    ->boolean(),

            ])
            ->filters([
                TrashedFilter::make(),
            ])
            ->recordActions([
                // ViewAction::make(),
                EditAction::make(),
            ])
            ->toolbarActions([
                BulkActionGroup::make([
                    DeleteBulkAction::make(),
                    ForceDeleteBulkAction::make(),
                    RestoreBulkAction::make(),
                ]),
            ]);
    }
}
