{% extends "base.html" %}
{% block title %}用户管理{% endblock %}
{% block content %}
<h1>用户管理</h1>
<table class="table table-striped">
    <thead>
        <tr>
            <th>ID</th>
            <th>用户名</th>
            <th>邮箱</th>
            <th>角色</th>
            <th>封禁状态</th>
            <th>注册时间</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
        {% for user in users %}
        <tr>
            <td>{{ user.id }}</td>
            <td>{{ user.username }}</td>
            <td>{{ user.email }}</td>
            <td>{{ user.role }}</td>
            <td>
                {% if user.banned == 0 %}
                    <span class="badge bg-success">正常</span>
                {% else %}
                    <span class="badge bg-danger">已封禁</span>
                {% endif %}
            </td>
            <td>{{ user.created_at }}</td>
            <td>
                <form action="{{ url_for('toggle_ban_user', id=user.id) }}" method="post" style="display:inline;">
                    {% if user.banned == 0 %}
                    <button type="submit" class="btn btn-warning btn-sm" onclick="return confirm('确定封禁该用户？')">封禁</button>
                    {% else %}
                    <button type="submit" class="btn btn-success btn-sm" onclick="return confirm('确定解封该用户？')">解封</button>
                    {% endif %}
                </form>
            </td>
        </tr>
        {% endfor %}
    </tbody>
</table>
{% endblock %}