{% extends 'admin/master.html' %}
{% block body %}
  <div style="float: right">
    <a type="button" class="btn btn-default" href="{{ url_for('statsview.top_ips', days=1) }}">last day</a>
    <a type="button" class="btn btn-default" href="{{ url_for('statsview.top_ips', days=7) }}">last week</a>
    <a type="button" class="btn btn-default" href="{{ url_for('statsview.top_ips', days=30) }}">last month</a>
  </div>
  <h1>Top IP addresses -- {{ days }} days</h1>

    <h2>Non commercial supporters</h2>
    <p>
       Supporters in good standing are not listed here.
    </p>
    {{ supporter_list(non_commercial, True) }}

    <h2>Commercial supporters</h2>
    {{ supporter_list(commercial, False) }}

{% endblock %}

{% macro supporter_list(supporters, show_usage) -%}
  {% if supporters %}
    <table class="table table-striped table-condensed">
      <thead>
      <tr>
        <th>IP</th>
        <th>Supporter</th>
        <th>Name</th>
        <th>Email</th>
        <th>Data usage</th>
        <th>Count</th>
      </tr>
      </thead>
      {% for ip, token, supporter_name, supporter_id, contact_name, contact_email, data_usage_desc, count in supporters %}
        <tr>
          <td>
            {{ ip }}
          </td>
          <td><a href="{{ url_for('supportersview.details', supporter_id=supporter_id) }}">{{ supporter_name }}</a></td>
          <td>{{ contact_name }}</td>
          <td>{{ contact_email }}</td>
          <td>
          {% if show_usage %}
             {{ data_usage_desc }}
          {% else %}
             <code class="text-muted">{{ token }}</code>
          {% endif %}
          </td>
          <td>{{ count }}</td>
        </tr>
      {% endfor %}
    </table>
  {% else %}
    None!
  {% endif %}
{% endmacro %}
