{% extends "html1/base.html" %}
{% block header %}
<div class="container">
  <h1>{{ title|default('Test Report') }}</h1>
</div>
{% endblock %}
{% block content %}
<div class="container">
  <div class="summary">
    {% block summary %}
    <div class="metadata">
      <table>
        <tr>
          <td>Started</td>
          <td>{{ started|strftime('%Y-%m-%d %H:%M:%S') }}</td>
        </tr>
        <tr>
          <td>Ended</td>
          <td>{{ started|strftime('%Y-%m-%d %H:%M:%S') }}</td>
        </tr>
        <tr>
          <td>Duration</td>
          {% set duration = ended - started %}
          <td>{{ duration|timedelta }}</td>
        </tr>
        {% if config._metadata %}
        {% for key, value in config._metadata.items() %}
        <tr>
          <td>{{ key }}</td>
          <td>
            {% if value is mapping %}
              {% for key, value in value.items() %}
                {{ key }}: {{ value }}<br/>
              {% endfor %}
            {% else %}
              {{ value }}
            {% endif %}
          </td>
        </tr>
        {% endfor %}
        {% endif %}
      </table>
    </div>
    <div class="donut">
      {% include "html1/chart.svg" %}
    </div>
    <ul class="statistics">
      {% for category, tests in test_runs|groupby('status.category') %}
        <li class="{{ category }} {{ tests|map(attribute='status.style')|first|join(' ') }}">
          {{ tests|count }} {{ category }}
        </li>
      {% endfor %}
    </ul>
    {% endblock %}
  </div>
  <ol class="test-files">
    {% for fspath, tests in test_runs|groupby('item.fspath') %}
    {% set item = tests|map(attribute='item.parent')|first %}
    <li class="collapsable">
      <div class="title">
        <div class="fspath">
          {{ item.listchain()|selectattr('parent')|join('/', attribute='name') }}
        </div>
        <div class="letters">
        {% for test in tests -%}
          {% for phase in test.phases if phase.status.letter -%}
            <span class="{{ phase.status.category }} {{ phase.status.style|join(' ') }}">{{ phase.status.letter }}</span>
          {%- endfor %}
        {%- endfor %}
        </div>
      </div>
      <div class="content">
        {% block module scoped %}
          {% include "html1/module.html" %}
        {% endblock %}
      </div>
      {#
      <td class="result">{{ test.word }}</td>
      <td class="nodeid">{{ test.item.nodeid }}</td>
      <td class="started">{{ test.phases|map(attribute='call.start')|first|datetime|strftime('%H:%M:%S.%f') }}</td>
      <td class="duration">{{ test.phases|sum('report.duration')|round(1) }}s</td>
          {% for phase in test.phases %}
          <li class="{{ phase.report.when }} {{ phase.category }}">
              <h3>{{ phase.report.when|title }}</h3>
              <div>{{ phase.word }}</div>
              <span>
                  {{ phase.call.start|datetime|strftime('%H:%M:%S.%f') }}
              </span>
              <pre><code>{{ phase.report.longrepr }}</code></pre>
              <ol>
                  {% for record in phase.log_records %}
                  <li>{{ record.message }}</li>
                  {% endfor %}
              </ol>
              {% for section, content in phase.report.sections %}
                  <h4>{{ section }}</h4>
                  <div>
                      {{ content }}
                  </div>
              {% endfor %}
          </li>
          {% endfor %}
      #}
    </li>
    {% endfor %}
  </ol>
</div>
{% endblock %}
