{% import "Juice/macros/forms.html" as forms with context %}
{% import "Juice/macros/widget.html" as widget with context %}
{% include "Juice/Plugin/Publisher/Admin/_include.html" %}

<div class="page-category">
    <div class="pull-right">
        <div class="btn btn-info"
                data-toggle="modal"
                data-target="#modal-cat-type"
                data-id=""
                data-name=""
                data-slug=""
                >New Category</div>
    </div>
    <div class="clearfix"></div>
<br>

{% call widget.panel("Categories", type="table") %}
    <table class="table table-bordered">
        <thead>
            <th>Name</th>
            <th>Slug</th>
            <th>Posts</th>
        </thead>

        <tbody>
            {% for cat in categories %}
            <tr>
                <td>
                <a href="javascript:"
                data-toggle="modal"
                data-target="#modal-cat-type"
                data-id="{{ cat.id }}"
                data-name="{{ cat.name }}"
                data-slug="{{ cat.slug}}">
                     {{ cat.name }}</a>
                </td>
                <td>{{ cat.slug }}</td>
                <td><a href="{{ url_for('PublisherAdmin:index', category_id=cat.id) }}">{{ cat.total_posts }}</a></td>
            </tr>
            {% endfor %}
        </tbody>

    </table>

{% endcall %}


</div>


<!-- MODAL -->
{% call widget.modal('Edit Category', id="modal-cat-type") %}
    <footer>
        <button type="submit" class="btn btn-success pull-left"><i class="fa fa-check"></i> SAVE</button>
        <button type="button" class="btn btn-default pull-left" data-dismiss="modal">Close</button>

        <button type="button" class="btn btn-danger delete-btn" data-dismiss="modal"><i class="fa fa-trash"></i> Delete</button>
    </footer>

    {% call forms.post('PublisherAdmin:categories') %}
        {{ forms.hidden(name="id", value="") }}
        {{ forms.hidden(name="action", value="") }}
        {{ forms.input(label="Name", name="name", value="", data={"validation": "required"}) }}
        {{ forms.input(label="Slug", name="slug", value="") }}
    {% endcall %}

{% endcall %}
