<?php

namespace App\Filament\Central\Widgets;

use App\Models\Central\Company;
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;

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

    protected function getStats(): array
    {
        $total = Company::count();
        $active = Company::where('status', 'active')->count();
        $trial = Company::where('status', 'trial')->count();
        $expiring = Company::where('status', 'active')
            ->whereNotNull('active_until')
            ->whereDate('active_until', '<=', now()->addDays(7))
            ->count();

        return [
            Stat::make('Companii total', $total)
                ->icon('heroicon-o-building-office-2')
                ->color('primary'),
            Stat::make('Active', $active)
                ->icon('heroicon-o-check-circle')
                ->color('success'),
            Stat::make('Trial', $trial)
                ->icon('heroicon-o-clock')
                ->color('warning'),
            Stat::make('Expiră în 7 zile', $expiring)
                ->description($expiring > 0 ? 'Atenție!' : 'Toate ok')
                ->icon('heroicon-o-exclamation-triangle')
                ->color($expiring > 0 ? 'danger' : 'success'),
        ];
    }
}
