{% extends "html1/base.html" %}
{% block header %}
<div class="container">
  <h1>{{ title|default('Test Report') }}</h1>
</div>
{% endblock %}
{% block content %}
<div class="container">
  <section class="summary">
    {% block summary %}
    <div class="metadata">
      <table>
        {% block metadata %}
        <tr>
          <td class="key">Started</td>
          <td class="value">{{ started|strftime('%Y-%m-%d %H:%M:%S') }}</td>
        </tr>
        <tr>
          <td class="key">Ended</td>
          <td class="value">{{ ended|strftime('%Y-%m-%d %H:%M:%S') }}</td>
        </tr>
        <tr>
          <td class="key">Duration</td>
          {% set duration = ended - started %}
          <td class="value">{{ duration|timedelta }}</td>
        </tr>
        {% if config._metadata %}
          {% for key, value in config._metadata.items() %}
            <tr>
              <td class="key">{{ key }}</td>
              <td class="value">
                {% if value is mapping %}
                  {% for key, value in value.items() %}
                    {{ key }}: {{ value }}<br/>
                  {% endfor %}
                {% else %}
                  {{ value|urlize }}
                {% endif %}
              </td>
            </tr>
            {% endfor %}
        {% endif %}
        {% endblock %}
      </table>
    </div>
    <div class="graph">
      {% include "html1/chart.svg" %}
      <div class="legend">
        {% for category, tests in tests|groupby('status.category') %}
          <span class="status badge {{ category }} {{ tests|map(attribute='status.style')|first|join(' ') }}">
            {{ tests|count }}
          </span>
          <span>{{ category }}</span>
        {% endfor %}
      </div>
    </div>
    {% endblock %}
  </section>
  {% if warnings %}
    <section class="warnings">
      {% for warning in warnings %}
        <div class="status badge warning">WARNING</div>
        <div>{{ warning.filename }}:{{ warning.lineno }}<br>{{ warning.message }}</div>
      {% endfor %}
    </section>
  {% endif %}
  <section class="test-files">
    {% for fspath, tests in tests|groupby('item.fspath') %}
      {% set item = tests|map(attribute='item.parent')|first %}
      <details class="file">
        <summary class="title">
          {% block module_title scoped %}
          <h2 class="fspath">
            {{ fspath|replace(config.rootdir, '')|replace('\\', '/') }}
          </h2>
          <div class="counts">
          {% for category, tests in tests|groupby('status.category') -%}
            <div title="{{ tests|count }} {{ category }}" class="status badge {{ category }} {{ tests|map(attribute='status.style')|first|join(' ') }}">{{ tests|count }}</div>
          {%- endfor %}
          </div>
          {% endblock %}
        </summary>
        <div class="content">
          {% block module_content scoped %}
            {% include "html1/module.html" %}
          {% endblock %}
        </div>
      </details>
    {% endfor %}
  </section>
</div>
{% endblock %}
