<?php

declare(strict_types=1);

namespace App\Filament\Widgets;

use App\Filament\Resources\WithdrawalRequests\WithdrawalRequestResource;
use App\Models\WithdrawalRequest;
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;

class PendingWithdrawalsOverview extends BaseWidget
{
    protected static ?int $sort = 1;

    protected function getStats(): array
    {
        $pending = WithdrawalRequest::query()
            ->where('status', WithdrawalRequest::STATUS_PENDING)
            ->count();

        $amount = (int) WithdrawalRequest::query()
            ->where('status', WithdrawalRequest::STATUS_PENDING)
            ->sum('amount');

        return [
            Stat::make('درخواست‌های برداشت در انتظار', $pending)
                ->description($amount > 0
                    ? \Illuminate\Support\Number::format($amount) . ' تومان در صف تایید'
                    : 'درخواستی در انتظار نیست')
                ->descriptionIcon('heroicon-m-banknotes')
                ->color($pending > 0 ? 'warning' : 'success')
                ->url(WithdrawalRequestResource::getUrl('index')),
        ];
    }
}
