<?php

namespace App\Filament\Widgets;

use App\Support\AdminDashboard;
use Filament\Widgets\StatsOverviewWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;

class MoneywiseStats extends StatsOverviewWidget
{
    protected static ?int $sort = -5;

    protected static bool $isLazy = false;

    protected ?string $heading = 'Journey health';

    protected ?string $description = 'The signals that show whether members are moving, learning and buying.';

    protected int|array|null $columns = ['md' => 2, 'xl' => 3];

    protected function getStats(): array
    {
        $data = app(AdminDashboard::class)->snapshot();

        return [
            Stat::make('Members', number_format($data['members']))
                ->description(number_format($data['leads']).' unique leads in the audience')
                ->descriptionIcon('heroicon-m-users')
                ->color('primary')
                ->url(url('/admin/users')),

            Stat::make('Financial baselines', number_format($data['assessments']))
                ->description('Completed assessments, member and guest')
                ->descriptionIcon('heroicon-m-heart')
                ->color('info')
                ->url(url('/admin/assessment-attempts')),

            Stat::make('Members with a plan', number_format($data['plans']))
                ->description('Saved at least one dashboard tool')
                ->descriptionIcon('heroicon-m-calculator')
                ->color('warning')
                ->url(url('/admin/users')),

            Stat::make('Active enrollments', number_format($data['enrollments']))
                ->description($data['courseCompletionRate'].'% course completion rate')
                ->descriptionIcon('heroicon-m-academic-cap')
                ->color('info')
                ->url(url('/admin/courses')),

            Stat::make('Checkout conversion', $data['checkoutConversion'].'%')
                ->description($data['paidCount'].' paid from '.$data['checkoutCount'].' attempts')
                ->descriptionIcon('heroicon-m-credit-card')
                ->color($data['checkoutConversion'] >= 25 ? 'success' : ($data['checkoutCount'] ? 'warning' : 'gray'))
                ->url(url('/admin/payments')),

            Stat::make('Verified revenue', 'KES '.number_format($data['revenueKes'] / 100))
                ->description('USD '.number_format($data['revenueUsd'] / 100, 2).' tracked separately')
                ->descriptionIcon('heroicon-m-banknotes')
                ->color('success')
                ->url(url('/admin/payments')),
        ];
    }
}
