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

<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 mb-3">
    <h5 class="card-header">Sync Log</h5>
    <div class="card-body">
      <table class="table table-hover panel-body">
        <tr>
          <th>Line</th>
          <th>Level</th>
          <th>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">
              No log output
            </td>
          </tr>
        {% endfor %}
      </table>
    </div>
    {% if execution_time %}
      <div class="card-footer text-end text-muted">
        <small>Exec Time: {{ execution_time|floatformat:3 }}s</small>
      </div>
    {% endif %}
  </div>
  <h4>Output</h4>
  <table class="table table-hover">
    <tr>
      <th>Action</th>
      <th>Zone</th>
      <th>Server</th>
      <th>Record</th>
    </tr>
    {% for output in job.data.output %}
      <tr>
        <td>{{ output.action }}</td>
        <td>{{ output.zone }}</td>
        <td>{{ output.server }}</td>
        <td>{{ output.rr }}</td>
      </tr>
    {% empty %}
      <tr>
        <td colspan="4" class="text-end text-muted">No changes</td>
      </tr>
    {% endfor %}
  </table>
{% elif job.started %}
  {% include 'extras/inc/result_pending.html' %}
{% endif %}
