{% extends "base.html" %}

{% block content %}
<br>
<img alt="VVF" src="./resources/images/owner.png" width="150"
  style="display: block; margin-left: auto; margin-right: auto;">
<br>
<p style="text-align: center;">
  <a id='add' href="edit_training.php?add">{{ 'Add training'|t }}</a>
</p>
<br>
<table style="width:100%">
  <tr class="tHead">
    <th>{{ 'Date'|t }}</th>
    <th>{{ 'Name'|t }}</th>
    <th>{{ 'Start time'|t }}</th>
    <th>{{ 'End time'|t }}</th>
    <th>{{ 'Chief'|t }}</th>
    <th>{{ 'Crew'|t }}</th>
    <th>{{ 'Place'|t }}</th>
    <th>{{ 'Notes'|t }}</th>
    {% if option('training_edit') %}
    <th>{{ 'Edit'|t }}</th>
    {% endif %}
    {% if option('training_remove') %}
    <th>{{ 'Remove'|t }}</th>
    {% endif %}
  </tr>
{% for row in query_results %}
  <tr class="tBody">
    <th>{{ row.date }}</th>
    <th>{{ row.name }}</th>
    <th>{{ row.beginning }}</th>
    <th>{{ row.end }}</th>
    <th>{{ username(row.chief) }}</th>
    <th>{{ username_list(row.crew) }}</th>
    <th>
      {% if "#" in row.place %}
      {% set mapImageID = row.place|split('#')[1] %}
      {% set place = row.place|split('#')[0] %}
      {% set place_lat = place|split(';')[0] %}
      {% set place_lng = place|split(';')[1] %}
      <img src="resources/images/map_cache/{{ mapImageID }}.png"></img><br>
      {% endif %}
      <a href="https://www.google.com/maps/search/?api=1&query={{ place_lat }},{{ place_lng }}" target="_blank">Apri la mappa in Google Maps</a><br>
      <a href="https://www.openstreetmap.org/#map=18/{{ place_lat }}/{{ place_lng }}" target="_blank">Apri la mappa in OpenStreetMap</a><br>
      Lat: <b>{{ place_lat }}</b><br>
      Lng: <b>{{ place_lng }}</b><br>
    </th>
    <th>{{ row.notes }}</th>
    {% if option('training_edit') %}
    <th><a href='edit_training.php?edit&id={{ row.id }}'>Modifica</a></th>
    {% endif %}
    {% if option('training_remove') %}
    <th><a href='edit_training.php?delete&id={{ row.id }}'>Rimuovi</a></th>
    {% endif %}
  </tr>
{% endfor %}
</table>
<br>
<br>
{% endblock %}