<?php
namespace App\Controllers;

use App\Core\Controller;
use App\Core\Database;

class SuperAdminUserController extends Controller
{
    public function index()
    {
        if (!is_super_admin()) exit('Forbidden');

        $db = Database::getInstance();
        $users = $db->query("
            SELECT u.*, o.name as org_name
            FROM users u
            LEFT JOIN organizations o ON u.org_id = o.id
            ORDER BY u.id DESC
        ")->fetchAll();

        $this->view('superadmin/users/index', compact('users'));
    }

    public function delete()
    {
        if (!is_super_admin()) exit('Forbidden');

        $db = Database::getInstance();
        $db->prepare("DELETE FROM users WHERE id=?")
           ->execute([(int)$_GET['id']]);

        echo "User deleted.";
    }
}
