{% extends 'fittings/base.html' %}
{% load i18n %}
{% load humanize %}
{% load filters %}


{% block page_title %}{% translate "View All Categories" %}{% endblock %}

{% block fittings_block %}
    {% if msg %}
        <div class="alert alert-{{ msg.0 }} alert-dismissible" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="close">
                <span aria-hidden="true">&times</span>
            </button>
            <h4>
                {% if msg.0 == 'danger' %}
                    {% translate "Oh No!" %}
                {% elif msg.0 == 'success' %}
                    {% translate "Success!" %}
                {% endif %}
            </h4>
            <p>{{ msg.1 }}</p>
        </div>
    {% endif %}

    <div>
        <h2>
            {% translate "Category List" %}
        </h2>

        <div class="panel panel-default">
            <div class="panel-heading">
                <div class="panel-title">{% translate "Fits" %}</div>
            </div>

            <div class="panel-body">
                {% if not cats %}
                    <div class="alert alert-warning text-center">{% translate "No Categories Found" %}</div>
                {% else %}
                    <table class="table table-striped table-hover dataTable" id="fitTable">
                        <thead>
                            <th>{% translate "Name" %}</th>
                            <th>{% translate "Doctrines Assigned" %}</th>
                            <th>{% translate "Fittings Assigned" %}</th>
                            {% if perms.fittings.manage %}
                                <th>{% translate "Groups Assigned" %}</th>
                                <th> </th>
                            {% endif %}
                        </thead>

                        <tbody>
                            {% for cat in cats %}
                                <tr>
                                    <td> <span class="label" style="background-color: {{cat.color}};"><a href="{% url 'fittings:view_category' cat.pk %}" class="nostyle">{{cat.name}}</a></span> </td>
                                    <td> {{ cat.doctrines_count }}</td>
                                    <td> {{ cat.total_fits }} </td>
                                    {% if perms.fittings.manage %}
                                        <td> {{ cat.groups_count }}</td>
                                        <td>
                                            <a href="{% url 'fittings:view_category' cat.pk %}" type="button" class="btn btn-sm btn-primary" data-toggle="tooltip" data-placement="top" title="{% translate 'View Category' %}">
                                                <span class="fa fas fa-eye"></span>
                                            </a>
                                            <a href="{% url 'fittings:edit_category' cat.pk %}" type="button" class="btn btn-sm btn-warning" data-toggle="tooltip" data-placement="top" title="{% translate 'Edit Category' %}">
                                                <span class="fa fas fa-pencil-alt"></span>
                                            </a>
                                            <a href="{% url 'fittings:delete_category' cat.pk %}" type="button" class="btn btn-sm btn-danger" data-toggle="tooltip" data-placement="top" title="{% translate 'Delete Category' %}">
                                                <span class="fa fas fa-times"></span>
                                            </a>
                                        </td>
                                    {% endif %}
                                </tr>
                            {% endfor %}
                        </tbody>
                    </table>

                    <h6>
                        <i class="fas fa-exclamation-triangle"></i>
                        <i>{% translate "*Note: Fit counts may be inaccurate as fits marked independently of doctrines may be counted more than once." %}</i>
                    </h6>
                {% endif %}
            </div>
        </div>
    </div>
{% endblock %}

{% block extra_javascript %}
    {% include 'bundles/datatables-js.html' %}
    <script>
        $(document).ready(function() {
            {% if cats %}
                $('#fitTable').DataTable();
            {% endif %}

            $('[data-toggle="tooltip"]').tooltip();
        });
    </script>
{% endblock %}

{% block extra_script %}

{% endblock %}
