<?php
namespace App\Controllers;

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

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

        $db = Database::getInstance();

        $organizations = $db->query("
            SELECT o.*,
                   (SELECT COUNT(*) FROM conferences c WHERE c.org_id=o.id) AS conferences_count,
                   (SELECT COUNT(*) FROM users u WHERE u.org_id=o.id) AS users_count
            FROM organizations o
            ORDER BY o.id DESC
        ")->fetchAll();

        ob_start();
        require BASE_PATH.'/app/views/admin/organizations/index.php';
        $content = ob_get_clean();

        require BASE_PATH.'/app/views/layouts/admin_layout.php';
    }
}
