<?php

namespace App\Filament\Resources\Products\Widgets;

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

class ProductStats extends BaseWidget
{
    protected function getStats(): array
    {
        $totalProducts = Product::count();
        $totalInventory = Product::sum('quantity');
        $averagePrice = Product::avg('price') ?? 0.00;

        return [
            Stat::make('Total Products', $totalProducts)
                ->description('Total products in catalog')
                ->descriptionIcon('heroicon-m-squares-2x2')
                ->color('info'),
            Stat::make('Product Inventory', $totalInventory)
                ->description('Total stock in inventory')
                ->descriptionIcon('heroicon-m-archive-box')
                ->color('success'),
            Stat::make('Average price', number_format($averagePrice, 2))
                ->description('Average product retail price')
                ->descriptionIcon('heroicon-m-currency-dollar')
                ->color('success'),
        ];
    }
}
