<?php /** @var array $users */ /** @var string $error */ /** @var string $ok */ ?>
<div class="page-head">
    <div><h1>用户管理</h1><div class="desc">管理后台账号与权限：超级管理员 / 管理员 / 用户 / 无（纯子系统账号），支持多人协同编辑</div></div>
    <a class="btn-primary" href="<?php echo site_url('admin/users/create'); ?>">+ 新增用户</a>
</div>

<?php if ($ok): ?><div class="alert alert-ok"><?php echo $ok; ?></div><?php endif; ?>
<?php if ($error): ?><div class="alert alert-err"><?php echo e($error); ?></div><?php endif; ?>

<div class="admin-card">
    <table class="admin-table">
        <tr><th>账号</th><th>姓名</th><th>角色</th><th>状态</th><th>操作</th></tr>
        <?php foreach ($users as $u): ?>
            <tr>
                <td><?php echo e($u['username']); ?></td>
                <td><?php echo e($u['name'] ?? ''); ?></td>
                <td><span class="role-badge role-<?php echo e($u['role'] ?? 'super_admin'); ?>"><?php echo e(admin_role_label($u['role'] ?? 'super_admin')); ?></span></td>
                <td><?php echo (($u['status'] ?? 1) ? '启用' : '停用'); ?></td>
                <td>
                    <div class="row-actions">
                        <a class="btn-soft btn-sm" href="<?php echo site_url('admin/users/edit/' . $u['id']); ?>">编辑</a>
                        <a class="btn-ghost btn-sm" href="<?php echo site_url('admin/users/reset/' . $u['id']); ?>" data-confirm="确定重置该用户密码？">重置密码</a>
                        <?php if (($u['id'] ?? 0) != admin_uid()): ?>
                        <a class="btn-danger btn-sm" href="<?php echo site_url('admin/users/destroy/' . $u['id']); ?>" data-confirm="确定删除该用户？">删除</a>
                        <?php endif; ?>
                    </div>
                </td>
            </tr>
        <?php endforeach; ?>
    </table>
</div>
