{% load helpers %}
{% load log_levels %}
{% load i18n %}

<div class="htmx-container">
  <p>
    {% if job.started %}
      {% trans "Started" %}: <strong>{{ job.started|isodatetime }}</strong>
    {% elif job.scheduled %}
      {% trans "Scheduled for" %}: <strong>{{ job.scheduled|isodatetime }}</strong>
    {% else %}
      {% trans "Created" %}: <strong>{{ job.created|isodatetime }}</strong>
    {% endif %}
    {% if job.completed %}
      {% trans "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 %}
    {% if tests %}
      {# Summary of test methods #}
      <div class="card">
        <h2 class="card-header">{% trans "Test Summary" %}</h2>
        <table class="table table-hover">
          {% for test, data in tests.items %}
            <tr>
              <td class="font-monospace">{{ test }}</td>
              <td class="text-end report-stats">
                <span class="badge text-bg-success">{{ data.success }}</span>
                <span class="badge text-bg-info">{{ data.info }}</span>
                <span class="badge text-bg-warning">{{ data.warning }}</span>
                <span class="badge text-bg-danger">{{ data.failure }}</span>
              </td>
            </tr>
          {% endfor %}
        </table>
      </div>
    {% endif %}

    {% if table %}
    <div class="card">
      <div class="table-responsive" id="object_list">
        <h2 class="card-header">{% trans "Log" %}</h2>
        <div class="htmx-container table-responsive"
          hx-get="{% url 'extras:script_result' job_pk=job.pk %}?embedded=True&log=True&log_threshold={{log_threshold}}"
          hx-target="this"
          hx-trigger="load" hx-select=".htmx-container" hx-swap="outerHTML">
        </div>
      </div>
    </div>
    {% endif %}

    {# Script output. Legacy reports will not have this. #}
    {% if 'output' in job.data %}
      <div class="card mb-3">
        <h2 class="card-header d-flex justify-content-between">
          {% trans "Output" %}
          {% if job.completed %}
            <div>
              <a href="?export=output" class="btn btn-sm btn-primary" role="button">
                <i class="mdi mdi-download" aria-hidden="true"></i> {% trans "Download" %}
              </a>
              {% copy_content "job_data_output" %}
            </div>
          {% endif %}
        </h2>
        {% if job.data.output %}
          <pre class="card-body font-monospace" id="job_data_output">{{ job.data.output }}</pre>
        {% else %}
          <div class="card-body text-muted">{% trans "None" %}</div>
        {% endif %}
      </div>
    {% endif %}

  {% elif job.started %}
    {% include 'extras/inc/result_pending.html' %}
  {% endif %}
</div>
