<?php
namespace Misuzu;

if(!$msz->isLoggedIn() || !perms_check_user(MSZ_PERMS_USER, $msz->getActiveUser()->getId(), MSZ_PERM_USER_MANAGE_ROLES)) {
    echo render_error(403);
    return;
}

$roles = $msz->getRoles();
$pagination = new Pagination($roles->countRoles(), 10);

if(!$pagination->hasValidOffset()) {
    echo render_error(404);
    return;
}

$rolesAll = [];
$roleInfos = $roles->getRoles(pagination: $pagination);

foreach($roleInfos as $roleInfo)
    $rolesAll[] = [
        'info' => $roleInfo,
        'members' => $roles->countRoleUsers($roleInfo),
    ];

Template::render('manage.users.roles', [
    'manage_roles' => $rolesAll,
    'manage_roles_pagination' => $pagination,
]);
