<?php

namespace App\Core\Dashboard\Controllers;

use App\Controllers\BaseController;
use App\Core\Ai\Models\AiHistoryModel;
use App\Core\Audit\Services\AuditService;
use App\Core\Auth\Models\UserModel;
use App\Core\License\Services\LicenseService;
use App\Core\Modules\Services\ModuleManager;

class DashboardController extends BaseController
{
    public function index()
    {
        $modules = new ModuleManager();
        $modules->sync();

        return view('core/dashboard/index', [
            'title' => 'Dashboard',
            'stats' => [
                'users' => (new UserModel())->countAllResults(),
                'modules' => count($modules->discover()),
                'ai_requests' => (new AiHistoryModel())->countAllResults(),
                'plan' => (new LicenseService())->getPlan(),
            ],
            'logs' => (new AuditService())->getRecentLogs(8),
        ]);
    }
}
