{% load i18n %}
{% load hro %}
{% load arrowfilter %}
<div id="activity-timeline" class="timeline">
  {% for a in activities %}
    <div class="activity" data-activity-id="{{ a.pk }}">
      <span class="timeline-icon{% if a.has_failed %} timeline-icon-failed{% endif %}">
        <i class="fa {% if not a.finished %}fa-refresh fa-spin {% else %}fa-{{a.icon}}{% endif %}"></i>
      </span>
      <strong title="{{ a.result.get_admin_text }}">
        <a href="{{ a.get_absolute_url }}">
          {{ a.readable_name.get_admin_text|capfirst }}</a>
      </strong>

    <span title="{{ a.started }}">{{ a.started|arrowfilter:LANGUAGE_CODE }}</span>{% if a.user %}, {{ a.user }}{% endif %}

    {% if a.children.count > 0 %}
      <div class="sub-timeline">
        {% for s in a.children.all %}
          <div data-activity-id="{{ s.pk }}"
               class="sub-activity{% if s.has_failed %} sub-activity-failed{% endif %}">
            <span title="{{ s.result.get_admin_text }}">
              <a href="{{ s.get_absolute_url }}">
                {{ s.readable_name|get_text:user }}</a>
            </span>
            &ndash;
            {% if s.finished %}
              <span title="{{ s.finished }}">
                {{ s.finished|arrowfilter:LANGUAGE_CODE }}
              </span>
            {% else %}
              <i class="fa fa-refresh fa-spin" class="sub-activity-loading-icon"></i>
            {% endif %}
            {% if s.has_failed %}
              <div class="label label-danger">{% trans "failed" %}</div>
            {% endif %}
          </div>
        {% endfor %}
      </div>
    {% endif %}
</div>
{% endfor %}
</div>

{% if show_show_all %}
<div id="show-all-activities-container">
  <a id="show-all-activities" href="#">
    {% if activities|length > 10 %}
      {% trans "Show less activities" %} <i class="fa fa-angle-double-up"></i>
    {% else %}
      {% trans "Show all activities" %} <i class="fa fa-angle-double-down"></i>
    {% endif %}
  </a>
</div>
{% endif %}
