<?php

namespace App\Filament\Resources\Orders\Widgets;

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

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

        return [
            Stat::make('Orders', $totalOrders)
                ->description('Total orders placed')
                ->descriptionIcon('heroicon-m-shopping-bag')
                ->color('info'),
            Stat::make('Open orders', $openOrders)
                ->description('Pending and processing orders')
                ->descriptionIcon('heroicon-m-clock')
                ->color('warning'),
            Stat::make('Average price', '৳' . number_format($averagePrice, 2))
                ->description('Average order total')
                ->descriptionIcon('heroicon-m-currency-bangladeshi')
                ->color('success'),
        ];
    }
}
