<?php

namespace App\Filament\Resources\ResellerOrders\Widgets;

use App\Models\Order;
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;

class ResellerOrderStats extends BaseWidget
{
    protected function getStats(): array
    {
        $totalOrders = Order::where('is_reseller_order', true)->count();
        $openOrders = Order::where('is_reseller_order', true)->whereIn('status', ['pending', 'processing'])->count();
        $averagePrice = Order::where('is_reseller_order', true)->avg('grand_total') ?? 0.00;

        return [
            Stat::make('Orders', $totalOrders)
                ->description('Total reseller orders')
                ->descriptionIcon('heroicon-m-shopping-bag')
                ->color('success'),
            Stat::make('Open Orders', $openOrders)
                ->description('Pending & processing')
                ->descriptionIcon('heroicon-m-arrow-path')
                ->color('warning'),
            Stat::make('Average Price', '৳' . number_format($averagePrice, 2))
                ->description('Average order value')
                ->descriptionIcon('heroicon-m-presentation-chart-bar')
                ->color('info'),
        ];
    }
}
