{% extends "newbase.html" %}
{% load staticfiles %}
{% load rowerfilters %}

{% block title %}Workouts{% endblock %}

{% block main %}
<h1>Workout {{ id }} Sensor Fusion</h1>
<ul class="main-content">
  <li>
    <table width=100%>
      <tr>
	<th>Rower:</th><td>{{ first_name }} {{ last_name }}</td>
      </tr><tr>
      <tr>
	<th>Name:</th><td>{{ workout.name }}</td>
      </tr><tr>
      <tr>
	<th>Date:</th><td>{{ workout.date }}</td>
      </tr><tr>
	<th>Time:</th><td>{{ workout.starttime }}</td>
      </tr><tr>
	<th>Distance:</th><td>{{ workout.distance }}m</td>
      </tr><tr>
	<th>Duration:</th><td>{{ workout.duration |durationprint:"%H:%M:%S.%f" }}</td>
      </tr><tr>
	<th>Type:</th><td>{{ workout.workouttype }}</td>
      </tr><tr>
	<th>Weight Category:</th><td>{{ workout.weightcategory }}</td>
      </tr>
    </table>
    <p>
      <form id="searchform" action=""
            method="get" accept-charset="utf-8">
        {{ searchform }}
        <input type="submit" value="GO"></input>
      </form>
    </p>
    <p>
      Select start and end date for a date range:
    </p>
    <p>
      <form enctype="multipart/form-data" action="/rowers/workout/fusion/{{ id }}/" method="post">
        
        <table>
          {{ dateform.as_table }}
        </table>
        {% csrf_token %}
    </p>
    <input name='daterange' type="submit" value="Submit">	</form>
  </li>
  <li class="grid_3">
    <h1>Fuse this workout with data from:</h1>
    {% if workouts %}
    <p>
      <span>
        {% if workouts.has_previous %}
        {% if request.GET.q %}
        <a href="?page=1&q={{ request.GET.q }}">
          <i class="fas fa-arrow-alt-to-left"></i>
        </a>
        <a href="?page={{ workouts.previous_page_number }}&q={{ request.GET.q }}">
          <i class="fas fa-arrow-alt-left"></i>
        </a>
        {% else %}
        <a href="?page=1">
          <i class="fas fa-arrow-alt-to-left"></i>
        </a>
        <a href="?page={{ workouts.previous_page_number }}">
          <i class="fas fa-arrow-alt-left"></i>
        </a>
        {% endif %}
        {% endif %}
        
        <span>
          Page {{ workouts.number }} of {{ workouts.paginator.num_pages }}.
        </span>
        
        {% if workouts.has_next %}
        {% if request.GET.q %}
        <a href="?page={{ workouts.next_page_number }}&q={{ request.GET.q }}">
          <i class="fas fa-arrow-alt-right"></i>
        </a>
        <a href="?page={{ workouts.paginator.num_pages }}&q={{ request.GET.q }}">
          <i class="fas fa-arrow-alt-to-right">
        </a>
        {% else %}
        <a href="?page={{ workouts.next_page_number }}">
          <i class="fas fa-arrow-alt-right"></i>
        </a>
        <a href="?page={{ workouts.paginator.num_pages }}">
          <i class="fas fa-arrow-alt-to-right"></i>
        </a>
        {% endif %}
        {% endif %}
      </span>
    </p>

    <table width="100%" class="listtable">
      <thead>
	<tr>
	  <th> Date</th>
	  <th> Time</th>
	  <th> Name</th>
	  <th> Type</th>
	  <th> Distance </th>
	  <th> Duration </th>
	  <th> Avg HR </th>
	  <th> Max HR </th>
	  <th> Fusion</th>
	</tr>
      </thead>
      <tbody>
        {% for cworkout in workouts %}
	<tr>
	  <td> {{ cworkout.date }} </td>
	  <td> {{ cworkout.starttime }} </td>
	  <td> <a href="/rowers/workout/{{ workout.id|encode }}/edit">{{ cworkout.name }}</a> </td>
	  <td> {{ cworkout.workouttype }} </td>
	  <td> {{ cworkout.distance }}m</td>
	  <td> {{ cworkout.duration |durationprint:"%H:%M:%S.%f" }} </td>
	  <td> {{ cworkout.averagehr }} </td>
	  <td> {{ cworkout.maxhr }} </td>
	  {% if id == cworkout.id %}
	  <td>&nbsp;</td>
	  {% else %}
	  <td> <a class="button blue small" href="/rowers/workout/fusion/{{ id }}/{{ cworkout.id|encode }}">Fusion</a> </td>
	  {% endif %}
          
	</tr>
	{% endfor %}
      </tbody>
    </table>
    {% else %}
    <p> No workouts found </p>
    {% endif %}
  </li>
</ul>
{% endblock %}

{% block sidebar %}
{% include 'menu_workout.html' %}
{% endblock %}
