<?php
namespace Misuzu;

if(!$msz->getAuthInfo()->getPerms('user')->check(Perm::U_ROLES_MANAGE))
    Template::throwError(403);

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

if(!$pagination->hasValidOffset())
    Template::throwError(404);

$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,
]);
