{% load i18n %}

<section>
  <div class="column-2">
    <div>
      {% if is_red_teamer %}
        <h1>{% translate 'Findings per organization' %}</h1>
      {% else %}
        <h1>{% translate 'Total findings' %}</h1>
      {% endif %}
      <table>
        <thead>
          <tr>
            <th>{% translate 'Organization' %}</th>
            <th scope="col" class="sortable" abbr="Sortable data">{% translate 'Total Findings' %}</th>
            <th scope="col">{% translate 'Details' %}</th>
          </tr>
        </thead>
        <tbody>
          {% for findings in findings_per_org_total %}
            {% spaceless %}
              <tr>
                <td>
                  {% if perms.tools.view_organization or request.user.is_superuser %}
                    <a href="{{ findings.organization.get_absolute_url }}">{{ findings.organization.name }}</a>
                  {% else %}
                    {{ findings.organization.name }}
                  {% endif %}
                </td>
                <td class="number">{{ findings|get_item:"meta"|get_item:"total" }}</td>
                <td>
                  <button class="expando-button"
                          data-icon-open-class="icon ti-chevron-down"
                          data-icon-close-class="icon ti-chevron-up"
                          data-close-label="{% translate 'Close details' %}">
                    {% translate 'Open details' %}
                  </button>
                </td>
              </tr>
              <tr class="expando-row">
                <td colspan="3">
                  <span class="sr-only">{{ org }} {% translate ' Finding Details' %}</span>
                  <h1>{{ org }} {% translate ' Finding Details' %}</h1>
                  <table>
                    <thead>
                      <th>{% translate 'Severity' %}</th>
                      <th>{% translate 'Occurences' %}</th>
                    </thead>
                    <tbody>
                      {% for key, value in findings.meta.total_by_severity.items %}
                        <tr>
                          <td>
                            <span class="{{ key }}">{{ key|title }}</span>
                          </td>
                          <td class="number">{{ value }}</td>
                        </tr>
                      {% endfor %}
                    </tbody>
                  </table>
                </td>
              </tr>
            {% endspaceless %}
          {% endfor %}
        </tbody>
      </table>
    </div>
    <div class="horizontal-scroll">
      {% if perms.tools.view_organization or request.user.is_superuser %}
        <h1>{% translate 'Top critical organizations' %}</h1>
      {% else %}
        <h1>{% translate 'Critical findings' %}</h1>
      {% endif %}
      <table>
        <thead>
          <tr>
            <th>{% translate 'Organization' %}</th>
            <th>{% translate 'Critical Findings' %}</th>
            <th scope="col">{% translate 'Details' %}</th>
          </tr>
        </thead>
        <tbody>
          {% for findings in findings_per_org_critical %}
            {% spaceless %}
              <tr>
                <td>
                  {% if perms.tools.view_organization or request.user.is_superuser %}
                    <a href="{% url 'organization_list' %}">{{ findings.organization.name }}</a>
                  {% else %}
                    {{ findings.organization.name }}
                  {% endif %}
                </td>
                <td class="number">{{ findings|get_item:"meta"|get_item:"total_by_severity"|get_item:"critical" }}</td>
                <td>
                  <button class="expando-button"
                          data-close-label="{% translate 'Close details' %}">
                    {% translate 'Open details' %}
                  </button>
                </td>
              </tr>
              <tr class="expando-row">
                <td colspan="3">
                  <span class="sr-only">{{ org }} {% translate ' Finding Details' %}</span>
                  <h1>{{ org }} {% translate ' Finding Details' %}</h1>
                  <ul>
                    {% for key, value in findings.meta.total_by_severity.items %}
                      <li>
                        <span class="{{ key }}">{{ key|title }} | {{ value }}</span>
                      </li>
                    {% endfor %}
                  </ul>
                </td>
              </tr>
            {% endspaceless %}
          {% endfor %}
        </tbody>
      </table>
    </div>
  </div>
</section>
