{% extends "base.html" %}

{% block content %}
<div class="container">


<div class="panel panel-success">
<div class="panel-heading"><h3 class="panel-title">Today</h3></div>
<table class="datatable table table-striped table-bordered">
  <theader>
    <tr>
      <th class="text-right">Senders</th>
      <th class="text-right">Receivers</th>
      <th class="text-right">Takeoffs</th>
      <th class="text-right">Landings</th>
      <th class="text-right">Sender Positions</th>
      <th class="text-right">Sender Positions Total</th>
    </tr>
  </theader>
  <tbody>
    <tr>
      <td class="text-right">{{ senders_today }}</td>
      <td class="text-right">{{ receivers_today }}</td>
      <td class="text-right">{{ takeoffs_today }}</td>
      <td class="text-right">{{ landings_today }}</td>
      <td class="text-right">{{ sender_positions_today }}</td>
      <td class="text-right">{{ sender_positions_total }}</td>
    </tr>
  </tbody>
</table>
</div>


<div class="panel panel-success">
<div class="panel-heading"><h3 class="panel-title">Logbook</h3></div>
<table class="datatable table table-striped table-bordered">
  <theader>
    <tr>
      <th></th>
      <th></th>
      <th colspan="2">Airport</th>
      <th colspan="2">Time UTC</th>
      <th></th>
      <th></th>
    </tr>
    <tr>
      <th>#</th>
      <th>Date</th>
      <th>Takeoff</th>
      <th>Landing</th>
      <th>Takeoff</th>
      <th>Landing</th>
      <th>Duration</th>
      <th>AGL</th>
    </tr>
  </theader>
  <tbody>
    {% set ns = namespace(mydate=none) %}
    {% for entry in logbook %}
    <tr>
      <td>{{ loop.index }}</td>
      <td>{% if ns.mydate != entry.reference_timestamp.strftime('%Y-%m-%d') %}{% set ns.mydate = entry.reference_timestamp.strftime('%Y-%m-%d') %}{{ ns.mydate }}{% endif %}</td>
      <td>{% if entry.takeoff_airport is not none %}<a href="{{ url_for('main.logbooks', country=entry.takeoff_airport.country_code, airport_id=entry.takeoff_airport.id, date=entry.reference_timestamp.strftime('%Y-%m-%d')) }}">{{ entry.takeoff_airport.name }}</a>{% endif %}</td>
      <td>{% if entry.landing_airport is not none %}<a href="{{ url_for('main.logbooks', country=entry.landing_airport.country_code, airport_id=entry.landing_airport.id, date=entry.reference_timestamp.strftime('%Y-%m-%d')) }}">{{ entry.landing_airport.name }}</a>{% endif %}</td>
      <td>{% if entry.takeoff_timestamp is not none %} {{ entry.takeoff_timestamp.strftime('%H:%M') }} {% endif %}</td>
      <td>{% if entry.landing_timestamp is not none %} {{ entry.landing_timestamp.strftime('%H:%M') }} {% endif %}</td>
      <td>{% if entry.duration is not none %}{{ entry.duration }}{% endif %}</td>
      <td>{% if entry.max_altitude is not none %}{{ '%0.1f'|format(entry.max_altitude - entry.takeoff_airport.altitude) }} m{% endif %}</td>
    </tr>
    {% endfor %}
  </tbody>
</table>
</div>
</div>

{% endblock %}


