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

{% block page_title %}{% translate "View All Fits" %}{% 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>

            {% if msg.0 != 'warning' %}
                <h4>
                    {% if msg.0 == 'danger' %}
                        {% translate "Oh No!" %}
                    {% elif msg.0 == 'success' %}
                        {% translate "Success!" %}
                    {% endif %}
                </h4>
            {% endif %}

            <p>{{ msg.1 }}</p>
        </div>
    {% endif %}

    <div>
        <h2>
            {% translate "Fit 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 fits %}
                    <div class="alert alert-warning text-center">{% translate "No Fits Found" %}</div>
                {% else %}
                    <table class="table table-striped table-hover dataTable" id="fitTable">
                        <thead>
                            <tr>
                                <th>{% translate "Ship Type" %}</th>
                                <th>{% translate "Name" %}</th>
                                <th>{% translate "Categories" %}</th>
                                <th>{% translate "Description" %}</th>
                            </tr>
                        </thead>

                        <tbody>
                            {% for fit in fits %}
                                <tr>
                                    <td>
                                        <a href="{% url 'fittings:view_fit' fit.pk %}" class="text-decoration-none d-inline-block">
                                            <img class="img-rounded" src="{{ fit.ship_type_type_id|type_render_url:32 }}" title="{{ fit.ship_type.type_name }}" alt="{{ fit.ship_type.type_name }}">
                                        </a>
                                        {{ fit.ship_type.type_name }}
                                    </td>
                                    <td><a href="{% url 'fittings:view_fit' fit.pk %}">{{ fit.name }}</a></td>
                                    <td>
                                        {% for cat in cats|get_item:fit.pk %}
                                        <span class="label" style="background-color: {{ cat.color }};"><a href="{% url 'fittings:view_category' cat.pk %}" class="nostyle">{{ cat.name }}</a></span>
                                        {% endfor %}
                                    </td>
                                    <td>{{ fit.description|linebreaks|urlize }}</td>
                                </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                {% endif %}
            </div>
        </div>
    </div>
{% endblock %}

{% block extra_javascript %}
    {% include 'bundles/datatables-js.html' %}

    <script>
        $(document).ready(function() {
            {% if fits %}
                $('#fitTable').DataTable();
            {% endif %}

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

{% block extra_script %}

{% endblock %}
