<?php
namespace App\Controllers;

use App\Core\Controller;
use App\Core\Database;
use App\Middleware\RoleGuard;

class AdminOwnerController extends Controller
{
    public function index()
    {
        RoleGuard::allow(['super_admin']);

        $db = Database::getInstance();

        $stats = [
            'organizations' => $db->query("SELECT COUNT(*) FROM organizations")->fetchColumn(),
            'active_orgs'   => $db->query("SELECT COUNT(*) FROM organizations WHERE is_active=1")->fetchColumn(),
            'conferences'   => $db->query("SELECT COUNT(*) FROM conferences")->fetchColumn(),
            'active_confs'  => $db->query("SELECT COUNT(*) FROM conferences WHERE is_active=1")->fetchColumn(),
            'submissions'   => $db->query("SELECT COUNT(*) FROM submissions")->fetchColumn(),
            'reviews'       => $db->query("SELECT COUNT(*) FROM reviews")->fetchColumn(),
            'users'         => $db->query("SELECT COUNT(*) FROM users")->fetchColumn(),
            'failed_jobs'   => $db->query("SELECT COUNT(*) FROM system_jobs WHERE status='failed'")->fetchColumn()
        ];

        $this->view('admin/owner/dashboard', compact('stats'));
    }
}
