{% load humanize %}
{% load helpers %}

<p>
  {% if job.started %}
    Started: <strong>{{ job.started|annotated_date }}</strong>
  {% elif job.scheduled %}
    Scheduled for: <strong>{{ job.scheduled|annotated_date }}</strong> ({{ job.scheduled|naturaltime }})
  {% else %}
    Created: <strong>{{ job.created|annotated_date }}</strong>
  {% endif %}
  {% if job.completed %}
    Duration: <strong>{{ job.duration }}</strong>
  {% endif %}
  <span id="pending-result-label">{% badge job.get_status_display job.get_status_color %}</span>
</p>
{% if job.completed %}
  <div class="card">
    <h5 class="card-header">Report Methods</h5>
    <div class="card-body">
      <table class="table table-hover">
        {% for method, data in job.data.items %}
          <tr>
            <td class="font-monospace"><a href="#{{ method }}">{{ method }}</a></td>
            <td class="text-end report-stats">
              <span class="badge bg-success">{{ data.success }}</span>
              <span class="badge bg-info">{{ data.info }}</span>
              <span class="badge bg-warning">{{ data.warning }}</span>
              <span class="badge bg-danger">{{ data.failure }}</span>
            </td>
          </tr>
        {% endfor %}
      </table>
    </div>
  </div>
  <div class="card">
    <h5 class="card-header">Report Results</h5>
    <div class="card-body">
      <table class="table table-hover report">
        <thead>
          <tr class="table-headings">
            <th>Time</th>
            <th>Level</th>
            <th>Object</th>
            <th>Message</th>
          </tr>
        </thead>
        <tbody>
          {% for method, data in job.data.items %}
            <tr>
              <th colspan="4" style="font-family: monospace">
                <a name="{{ method }}"></a>{{ method }}
              </th>
            </tr>
            {% for time, level, obj, url, message in data.log %}
              <tr class="{% if level == 'failure' %}danger{% elif level %}{{ level }}{% endif %}">
                <td>{{ time }}</td>
                <td>
                  <label class="badge bg-{% if level == 'failure' %}danger{% else %}{{ level }}{% endif %}">{{ level|title }}</label>
                </td>
                <td>
                  {% if obj and url %}
                    <a href="{{ url }}">{{ obj }}</a>
                  {% elif obj %}
                    {{ obj }}
                  {% else %}
                    {{ ''|placeholder }}
                  {% endif %}
                </td>
                <td class="rendered-markdown">{{ message|markdown }}</td>
              </tr>
            {% endfor %}
          {% endfor %}
        </tbody>
      </table>
    </div>
  </div>
{% elif job.started %}
  {% include 'extras/inc/result_pending.html' %}
{% endif %}
