<?php

namespace App\Filament\Resources\UpworkEarningResource\Pages;

use App\Filament\Resources\UpworkEarningResource;
use App\Models\UpworkEarning;
use Filament\Actions;
use Filament\Resources\Components\Tab;
use Filament\Resources\Pages\ListRecords;
use Illuminate\Database\Eloquent\Builder;

class ListUpworkEarnings extends ListRecords
{
    protected static string $resource = UpworkEarningResource::class;

    protected function getHeaderActions(): array
    {
        return [
            Actions\Action::make('importar')
                ->label('Importar CSV')
                ->icon('heroicon-o-arrow-up-tray')
                ->url(fn () => route('filament.admin.pages.upwork-import-page')),
        ];
    }

    public function getTabs(): array
    {
        return [
            'todos' => Tab::make('Todos')
                ->icon('heroicon-m-list-bullet'),

            'ganancias' => Tab::make('Ganancias')
                ->icon('heroicon-m-arrow-trending-up')
                ->modifyQueryUsing(fn (Builder $q) => $q->whereIn('payment_type', [
                    'Hourly', 'Fixed-price', 'Fixed Price', 'Bonus',
                ])),

            'retiros' => Tab::make('Retiros')
                ->icon('heroicon-m-arrow-right-on-rectangle')
                ->modifyQueryUsing(fn (Builder $q) => $q->whereIn('payment_type', [
                    'Withdrawal', 'Withdrawal Fee',
                ])),

            'gastos' => Tab::make('Gastos')
                ->icon('heroicon-m-receipt-percent')
                ->modifyQueryUsing(fn (Builder $q) => $q->whereIn('payment_type', [
                    'Connects', 'Subscription',
                ]))
                ->badgeColor('danger'),
        ];
    }
}
