{% extends 'base.html' %}
{% from 'bootstrap/form.html' import render_form %}

{% block title %}Manage Categories{% endblock %}

{% block content %}
    <div class="page-header">
        <h1>分类
            <small class="text-muted">{{ categories|length }}个</small>
            <span class="float-right"><a class="btn btn-primary btn-sm"
                                         href="{{ url_for('.new_category') }}">新分类</a></span>
        </h1>
    </div>
    {% if categories %}
        <table class="table table-striped">
            <thead>
            <tr>
                <th>次序</th>
                <th>名字</th>
                <th>文章数</th>
                <th>操作</th>
            </tr>
            </thead>
            {% for category in categories %}
                <tr>
                    <td>{{ loop.index }}</td>
                    <td><a href="{{ url_for('blog.show_category', category_id=category.id) }}">{{ category.name }}</a>
                    </td>
                    <td>{{ category.posts|length }}</td>
                    <td>
                        {% if category.id != 1 %}
                            <a class="btn btn-outline-info btn-sm"
                               href="{{ url_for('.edit_category', category_id=category.id) }}">编辑</a>

                            <form class="inline" method="post"
                                  action="{{ url_for('.delete_category', category_id=category.id) }}">
                                <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
                                <button type="submit" class="btn btn-outline-danger btn-sm"
                                        onclick="return confirm('Are you sure?');">删除
                                </button>
                            </form>
                        {% endif %}
                    </td>
                </tr>
            {% endfor %}
        </table>
        <p class="text-muted">提示:删除一个类别并不会删除该类别下的文章。这个类别下的文章将被移到默认类别。</p>
    {% else %}
        <div class="tip"><h5>没有分类</h5></div>
    {% endif %}
{% endblock %}
