{% extends 'admin/index.html' %}
{% from 'bootstrap/pagination.html' import render_pagination %}

{% block title %}管理评论{% endblock %}

{% block content %}
    <nav aria-label="breadcrumb">
        <ol class="breadcrumb">
            {{ render_breadcrumb_item('admin.index', '控制板主页') }}
            {{ render_breadcrumb_item('admin.manage_comment', '管理评论') }}
        </ol>
    </nav>
    <div class="page-header">
        <h1>评论
            <small class="text-muted">{{ pagination.total }}</small>
            <span class="dropdown">
            <button class="btn btn-secondary btn-sm" type="button" id="dropdownMenuButton" data-toggle="dropdown"
                    aria-haspopup="true" aria-expanded="false">
                Order by {{ order_rule }} <span class="oi oi-elevator"></span>
            </button>
            <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
                {% if order_rule == 'flag' %}
                    <a class="dropdown-item" href="{{ url_for('.manage_comment', order='by_time') }}">按时间顺序</a>
                {% else %}
                    <a class="dropdown-item" href="{{ url_for('.manage_comment', order='by_flag') }}">按标签顺序</a>
                {% endif %}
            </div>
        </span>
        </h1>
    </div>
    {% if comments %}
        <table class="table table-striped">
            <thead>
            <tr>
                <th>主体</th>
                <th>作者</th>
                <th>照片</th>
                <th>记录</th>
                <th>日期</th>
                <th>动作</th>
            </tr>
            </thead>
            {% for comment in comments %}
                <tr>
                    <td>{{ comment.body }}</td>
                    <td>
                        <a href="{{ url_for('user.index', username=comment.author.username) }}">{{ comment.author.name }}</a>
                    </td>
                    <td>
                        <a href="{{ url_for('main.show_photo', photo_id=comment.photo.id) }}">Photo {{ comment.photo.id }}</a>
                    </td>
                    <td>{{ comment.flag }}</td>
                    <td>{{ moment(comment.timestamp).format('LL') }}</td>
                    <td>
                        <form class="inline" method="post"
                              action="{{ url_for('main.delete_comment', comment_id=comment.id, next=request.full_path) }}">
                            <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
                            <button type="submit" class="btn btn-danger btn-sm"
                                    onclick="return confirm('Are you sure?');">删除
                            </button>
                        </form>
                    </td>
                </tr>
            {% endfor %}
        </table>
        <div class="page-footer">{{ render_pagination(pagination) }}</div>
    {% else %}
        <div class="tip"><h5>无评论</h5></div>
    {% endif %}
{% endblock %}