{% extends "base.html" %}

{% block content %}

<div class="container">
<div class="panel panel-success">
<div class="panel-heading"><h3 class="panel-title">Receiver Ranking</h3></div>
<div class="panel-body">

  <form>
    <div class="well">
    <select name="country" onchange="this.form.submit();">
      <option value="">(all)</option>
        {% for country in countries %}
        <option value="{{ country.iso2 }}"{% if sel_country == country.iso2 %} SELECTED{% endif %}>{{ country.iso2 }}</option>
        {% endfor %}
    </select>
    </div>
  </form>

  <table id="myTable" class="table table-striped table-bordered tablesorter tablesorter-bootstrap">
    <thead>
      <tr>
        <th class="text-right" colspan="2">Rank</th>
        <th class="text-right">Today</th>
        <th>Name</th>
        <th>Airport</th>
        <th class="text-right">Distance [km]</th>
        <th class="text-right">Senders</th>
        <th class="text-right">Coverages</th>
        <th class="text-right">Messages</th>
      </tr>
    </thead>

    <tbody>
    {% for (receiver, ranking, current, today, yesterday) in ranking %}
      <tr>
        <td class="text-right">{{ today }}</td>
        <td class="text-right">{% if yesterday is none %}(new){% elif yesterday - today > 0 %}<span class="text-success"><i class="fa fa-long-arrow-up"></i>{{ yesterday - today }}</span>{% elif yesterday - today < 0 %}<span class="text-danger"><i class="fa fa-long-arrow-down"></i>{{ today - yesterday }}</span>{% endif %}</td>
        <td class="text-right">{% if current is not none %}{{ current }}{% else %}-{% endif %}</td>
        <td>{{ receiver|to_html_flag|safe }}{{ receiver|to_html_link|safe }}</td>
        <td>{{ receiver.airport|to_html_link|safe }}</td>
        <td class="text-right">{% if ranking is not none %}{{ '%0.1f' | format(ranking.max_distance/1000.0) }}{% else %}-{% endif %}</td>
        <td class="text-right">{% if ranking is not none %}{{ ranking.senders_count }}{% else %}-{% endif %}</td>
        <td class="text-right">{% if ranking is not none %}{{ ranking.coverages_count }}{% else %}-{% endif %}</td>
        <td class="text-right">{% if ranking is not none %}{{ ranking.messages_count }}{% else %}-{% endif %}</td>
      </tr>
      {% endfor %}
    </tbody>
  </table>
</div>
</div>

{% endblock %}

{% block scripts %}
  {{ super() }}
  <script>
    $(function() {
      $("#myTable").tablesorter({
          stringTo:"bottom",
          theme:"bootstrap",
          headerTemplate:"{content} {icon}",
          widgets:["uitheme"]
        });
    });
  </script>
{% endblock %}
