{# -*- engine:django -*- #}

{% extends "core/base.html" %}
{% load data_helpers %}
{% load html_helpers %}

{% load i18n %}
{% load render_table from django_tables2 %}

{% block browser_title %}{% blocktrans %}Data checks{% endblocktrans %}{% endblock %}
{% block page_title %}{% blocktrans %}Data checks{% endblocktrans %}{% endblock %}

{% block content %}
  <a class="btn green waves-effect waves-light" href="{% url "data_check_run" %}">
    <i class="material-icons left iconify" data-icon="mdi:refresh"></i>
    {% trans "Check data again" %}
  </a>

  {% if results %}
    <div class="card">
      <div class="card-content">
        <i class="material-icons left medium red-text iconify" data-icon="mdi:alert-outline"></i>
        <span class="card-title">{% trans "The system detected some problems with your data." %}</span>
        <p>{% blocktrans %}Please go through all data and check whether some extra action is
          needed.{% endblocktrans %}</p>
      </div>
    </div>
  {% else %}
    <div class="card">
      <div class="card-content">
        <i class="material-icons left medium green-text iconify" data-icon="mdi:check-circle-outline"></i>
        <span class="card-title">{% trans "Everything is fine." %}</span>
        <p>{% blocktrans %}The system hasn't detected any problems with your data.{% endblocktrans %}</p>
      </div>
    </div>
  {% endif %}

  {% if results %}
    <div class="card">
      <div class="card-content">
        <div class="card-title">{% trans "Detected problems" %}</div>
        <table>
          <thead>
          <tr>
            <th></th>
            <th colspan="2">{% trans "Affected object" %}</th>
            <th>{% trans "Detected problem" %}</th>
            <th>{% trans "Show details" %}</th>
            <th>{% trans "Options to solve the problem" %}</th>
          </tr>
          </thead>
          <tbody>
          {% for result in results %}
            {% if result.related_object %}
              <tr>
                <td>
                  <code>{{ result.id }}</code>
                </td>
                <td>{% verbose_name_object result.related_object %}</td>
                <td>{{ result.related_object }}</td>
                <td>{{ result.related_check.problem_name }}</td>
                <td>
		  {% if result.related_object.get_absolute_url %}
                  <a class="btn-flat waves-effect waves-light" href="{{ result.related_object.get_absolute_url|remove_prefix:"/django/" }}" target="_blank">
                    {% trans "Show object" %}
                  </a>
		  {% endif %}
                </td>
                <td>
                  {% for option_name, option in result.related_check.solve_options.items %}
                    <a class="btn btn-margin waves-effect waves-light"
                       href="{% url "data_check_solve" result.pk option_name %}">
                      {{ option.verbose_name }}
                    </a>
                  {% endfor %}
                </td>
              </tr>
            {% endif %}
          {% endfor %}
          </tbody>
        </table>
      </div>
    </div>
  {% endif %}
  </div>

  <div class="card hundred-percent">
    <div class="card-content">
      <div class="card-title">{% trans "Registered checks" %}</div>
      <div class="alert primary">
        <div>
          <i class="material-icons left iconify" data-icon="mdi:information-outline"></i>
          {% blocktrans %}
            The system will check for the following problems:
          {% endblocktrans %}
        </div>
      </div>
      <ul class="collection">
        {% for check in registered_checks %}
          <li class="collection-item">
            <i class="material-icons left iconify" data-icon="mdi:check"></i>
            {{ check.verbose_name }}
          </li>
        {% endfor %}
      </ul>
    </div>
  </div>
{% endblock %}
