{% load dash_tags %}
<div class="card mb-4" id="{{ result.pk }}">
  <div class="card-body">
    <a href="{% url "dash:result_detail" jid=result.jid minion=result.minion  %}"
       class="float-right ml-1 badge badge-{% if result.was_success %}success{% else %}danger{% endif %}">
      {% if result.was_success %}√{% else %}x{% endif %}
    </a>
    {% if result.has_states %}
      <code class="float-right small text-muted">{{ result.duration|pretty_time }}</code>
    {% endif %}

    <h4 class="card-title">
      <code><a href="{% url "dash:result_detail" jid=result.jid minion=result.minion  %}">
        {{ result.minion }}
      </a></code>
    </h4>
    {% if show_job %}
    {% include "dash/_job_summary.html" with job=result.job %}
  {% endif %}

    {% if result.has_states %}
      {% if result.states_failed > 0 %}
        <a href="#"
           data-toggle="collapse-optimized"
           data-button-toggle-class="danger"
           data-target='div#result-{{ result.pk }}'
           data-target-status='failed'
           class="btn btn-sm btn-danger">{{ result.states_failed }} failed</a>
      {% endif %}

      {% if result.states_failed_requisite > 0 %}
        <a href="#"
           data-toggle="collapse-optimized"
           data-button-toggle-class="warning"
           data-target='div#result-{{ result.pk }}'
           data-target-status="requisite-failed"
           class="btn btn-sm btn-outline-warning">{{ result.states_failed_requisite }} failed req</a>
      {% endif %}

      {% if result.states_changed > 0 %}
        <a href="#"
           data-toggle="collapse-optimized"
           data-button-toggle-class="success"
           data-target='div#result-{{ result.pk }}'
           data-target-status="changed"
           class="btn btn-sm btn{% if collapsed %}-outline{% endif %}-success">{{ result.states_changed }} changed</a>
      {% endif %}

      {% if result.states_unchanged > 0 %}
        <a href="#"
           data-toggle="collapse-optimized"
           data-button-toggle-class="secondary"
           data-target='div#result-{{ result.pk }}'
           data-target-status='unchanged'
           class="btn btn-sm btn-outline-secondary">{{ result.states_unchanged }} unchanged</a>
      {% endif %}

      <div id="result-{{ result.pk }}" class="state-list-container state-failed{% if not collapsed %} state-changed{% endif %}">
        {% include "dash/_results/"|add:result.result_type|add:".html" with result=result %}
      </div>
    {% else %}

      {# not state output, just text/json #}
      {% if collapsed %}
      <a href="#result-{{ result.pk }}"
         data-toggle="collapse"
         class="text-muted{% if result.was_success %} collapsed{% endif %}">Show/hide results</a>
      {% endif %}
      {% if result.return_val %}
        <div id="result-{{ result.pk }}"
             class="collapse {% if not collapsed or not result.was_success %}show{% endif %}">
          {% include "dash/_results/"|add:result.result_type|add:".html" with result=result %}
        </div>
      {% endif %}
    {% endif %}
  </div>

  {% if result.completed %}
    <div class="card-footer text-muted">
      {{ result.completed }}
    </div>
  {% endif %}
</div>
