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

{% block django_datawatch %}
    {% with check_instance=result.get_check_instance %}
        <div class="row">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-header {% if result.status == result.STATUS.critical %}text-bg-danger{% elif result.status == result.STATUS.warning %}text-bg-warning{% elif result.status == result.STATUS.ok %}text-bg-success{% else %}panel-default{% endif %}">
                        <h5 class="card-title pt-2">{{ result.get_status_display }} - {{ check_instance.get_title }}</h5>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-8">
                                <h3>{{ result.payload_description }}</h3>
                            </div>
                            <div class="col-md-4 text-end">
                                {% if perms.django_datawatch.acknowledge %}
                                    <a href="{% url "django_datawatch_result_acknowledge" pk=result.pk %}">{% trans "Acknowledge" %}</a><br>
                                {% endif %}
                                {% if perms.django_datawatch.config and check_instance.get_form_class %}
                                    <a href="{% url "django_datawatch_result_config" pk=result.pk %}">{% trans "Change config" %}</a><br>
                                {% endif %}
                                {% if perms.django_datawatch.refresh %}
                                    <a href="{% url "django_datawatch_result_refresh" pk=result.pk %}">{% trans "Refresh" %}</a>
                                {% endif %}
                            </div>
                        </div>
                        {% if datawatch_show_debug_info %}
                            <div class="row">
                                <div class="col-md-12">
                                    <h4>{% trans "Superuser debug info" %}</h4>
                                    <table class="table table-striped">
                                        <tbody>
                                            <tr>
                                                <td>{% trans "Check module slug" %}</td>
                                                <td>{{ check_instance.slug }}</td>
                                            </tr>
                                            <tr>
                                                <td>{% trans "Related model" %}</td>
                                                <td>
                                                    {% if check_instance.model_class %}
                                                        {{ check_instance.model_class|class_name }}
                                                    {% else %}
                                                        {% trans "Not assigned" %}
                                                    {% endif %}
                                                </td>
                                            </tr>
                                            {% with form_class=check_instance.get_form_class %}
                                                <tr>
                                                    <td>{% trans "Config form class" %}</td>
                                                    <td>
                                                        {% if form_class %}
                                                            {{ form_class|class_name }}
                                                        {% else %}
                                                            {% trans "Not assigned" %}
                                                        {% endif %}
                                                    </td>
                                                </tr>
                                            {% endwith %}
                                            <tr>
                                                <td>{% trans "Config" %}</td>
                                                <td>
                                                    <pre>{{ result.config_formatted }}</pre>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>{% trans "Run every" %}</td>
                                                <td>
                                                    {% if check_instance.run_every %}
                                                        {{ check_instance.run_every }}
                                                    {% else %}
                                                        {% trans "Not set" %}
                                                    {% endif %}
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>{% trans "Update trigger models" %}</td>
                                                <td>
                                                    {% for value in check_instance.trigger_update.values %}
                                                        {{ value|class_name }}
                                                        {% if not forloop.last %}
                                                            <br>
                                                        {% endif %}
                                                    {% endfor %}
                                                </td>
                                            </tr>
                                            {% with max_acknowdledge=check_instance.get_max_acknowledge %}
                                                <tr>
                                                    <td>{% trans "Acknowledge maximum" %}</td>
                                                    <td>
                                                        {% if max_acknowdledge %}
                                                            {% blocktrans with days=max_acknowdledge %}{{ days }} day(s){% endblocktrans %}
                                                        {% else %}
                                                            {% trans "Not set" %}
                                                        {% endif %}
                                                    </td>
                                                </tr>
                                            {% endwith %}
                                            <tr>
                                                <td>{% trans "Assigned groups" %}</td>
                                                <td>
                                                    {% if result.assigned_groups.all %}
                                                        {{ result.assigned_groups.all|join:', ' }}
                                                    {% else %}
                                                        {% trans "Not set" %}
                                                    {% endif %}
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>{% trans "Assigned users" %}</td>
                                                <td>
                                                    {% if result.assigned_users.all %}
                                                        {{ result.assigned_users.all|join:', ' }}
                                                    {% else %}
                                                        {% trans "Not set" %}
                                                    {% endif %}
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        {% endif %}
                        {% if result.is_acknowledged %}
                            <div class="row">
                                <div class="col-md-12">
                                    <div class="alert alert-info">
                                        <p>
                                            {% blocktrans with date=result.acknowledged_until|date user=result.acknowledged_by %}Acknowledged until {{ date }} by {{ user }}{% endblocktrans %}
                                        </p>
                                        <p>
                                            <strong>{% trans "Reason:" %}</strong> {{ result.acknowledged_reason }}
                                        </p>
                                    </div>
                                </div>
                            </div>
                        {% endif %}
                        <div class="row mt-4">
                            <div class="col-md-12">
                                {% block django_datawatch_check %}{% endblock %}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    {% endwith %}
{% endblock %}
