{% 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 post in posts %}
        <tr>
            <td>{{ post.id }}</td>
            <td>{{ post.title }}</td>
            <td>{{ post.content[:50] }}{% if post.content|length > 50 %}...{% endif %}</td>
            <td>{{ post.username }}</td>
            <td>
                {% if post.banned == 0 %}
                    <span class="badge bg-success">正常</span>
                {% else %}
                    <span class="badge bg-danger">已封禁</span>
                {% endif %}
            </td>
            <td>{{ post.created_at }}</td>
            <td>
                <form action="{{ url_for('toggle_ban_post', id=post.id) }}" method="post" style="display:inline;">
                    {% if post.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 %}