{% extends "django_datawatch/base.html" %}
{% load i18n %}
{% load bootstrap3 %}

{% block django_datawatch %}
    <div class="row">
        <div class="col-md-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">{% trans "Filter" %}</h3>
                </div>
                <div class="panel-body">
                    <form method="get" class="form-horizontal">
                        {% bootstrap_form form layout='horizontal' %}
                        {% buttons %}
                            <div class="col-sm-offset-2 col-sm-10">
                                {% trans "Filter" as trans_filter %}
                                {% bootstrap_button trans_filter button_type="submit" button_class="btn-primary" %}
                            </div>
                        {% endbuttons %}
                    </form>
                </div>
            </div>
        </div>
    </div>

    {% regroup results by get_status_display as status_list %}
    <div class="row">
        {% if not status_list %}
            <div class="col-md-12">
                <div class="alert alert-info text-center">
                    <h3>{% trans "There is nothing to see here. Everything is fine!" %}</h3>
                </div>
            </div>
        {% else %}
            {% widthratio 12 status_list|length 1 as size %}
            {% for status in status_list %}
                {% for status_definition in view.queryset.get_stats %}
                    {% if status.grouper == status_definition.status_name %}
                        <div class="col-md-{{ size }}">
                            <a href="#status-{{ status_definition.status_name|slugify }}" class="btn col-md-12 {% if status_definition.status == check.STATUS.ok %}btn-success{% elif status_definition.status == check.STATUS.warning %}btn-warning{% elif status_definition.status == check.STATUS.critical %}btn-danger{% endif %}">
                                {{ status_definition.status_name }}<br>
                                <h3>{{ status_definition.amount }}</h3>
                            </a>
                        </div>
                    {% endif %}
                {% endfor %}
            {% endfor %}
        {% endif %}
    </div>

    <div class="row">
        <div class="col-md-12">
            {% for status in status_list %}
                <h1 id="status-{{ status.grouper|slugify }}">{{ status.grouper }}</h1>

                <table class="table table-bordered">
                    {% for result in status.list %}
                        <tr>
                            <td style="width: 20%;">
                                <span class="label label-{% if result.status == result.STATUS.critical %}danger{% elif result.status == result.STATUS.warning %}warning{% elif result.status == result.STATUS.ok %}success{% endif %}">{{ result.get_status_display }}</span>
                                {% if result.is_acknowledged %}
                                    <br>
                                    <span class="label label-default">{% blocktrans with date=result.acknowledged_until|date %}Acknowledged until {{ date }}{% endblocktrans %}</span>
                                {% endif %}
                            </td>
                            <td style="width: 40%;">
                                <a href="{% url "django_datawatch_result" pk=result.pk %}">
                                    <strong>{{ result.get_check_instance.get_title }}</strong>
                                </a>
                            </td>
                            <td style="width: 40%;">
                                {{ result.payload_description }}
                            </td>
                        </tr>
                    {% endfor %}
                </table>
            {% endfor %}
        </div>
    </div>
{% endblock %}
