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

<p>
  {% if job.started %}
    {% trans "Started" %}: <strong>{{ job.started|annotated_date }}</strong>
  {% elif job.scheduled %}
    {% trans "Scheduled for" %}: <strong>{{ job.scheduled|annotated_date }}</strong> ({{ job.scheduled|naturaltime }})
  {% else %}
    {% trans "Created" %}: <strong>{{ job.created|annotated_date }}</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 %}
  <div class="card mb-3">
    <h5 class="card-header">{% trans "Script Log" %}</h5>
    <div class="card-body">
      <table class="table table-hover panel-body">
        <tr>
          <th>{% trans "Line" %}</th>
          <th>{% trans "Level" %}</th>
          <th>{% trans "Message" %}</th>
        </tr>
        {% for log in job.data.log %}
          <tr>
            <td>{{ forloop.counter }}</td>
            <td>{% log_level log.status %}</td>
            <td class="rendered-markdown">{{ log.message|markdown }}</td>
          </tr>
        {% empty %}
          <tr>
            <td colspan="3" class="text-center text-muted">
              {% trans "No log output" %}
            </td>
          </tr>
        {% endfor %}
      </table>
    </div>
    {% if execution_time %}
      <div class="card-footer text-end text-muted">
        <small>{% trans "Exec Time" %}: {{ execution_time|floatformat:3 }} {% trans "seconds" context "Unit of time" %}</small>
      </div>
    {% endif %}
  </div>
  <h4>{% trans "Output" %}</h4>
  {% if job.data.output %}
    <pre class="block">{{ job.data.output }}</pre>
  {% else %}
    <p class="text-muted">{% trans "None" %}</p>
  {% endif %}
{% elif job.started %}
  {% include 'extras/inc/result_pending.html' %}
{% endif %}
