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

{% block title %}Planned Sessions{% endblock %}

{% block main %}
{% if theteam %}
<h1>Group Overview. Team {{ theteam.name }}</h1>
{% else %}
<h1>Group Overview</h1>
{% endif %}

<ul class="main-content">
  <li class="grid_2">
    <p>
      <form enctype="multipart/form-data" method="get">
        <table>
          {{ dateform.as_table }}
        </table>
        <input type="Submit" value="Set Date Range">
      </form>
    </p>
  </li>
  <li class="grid_2">
    <p><a href="/rowers/sessions/coach/?startdate={{ timeperiod|previousperiodstart }}&enddate={{ timeperiod|previousperiodend}}">Back by
        {{ timeperiod|timedeltadays }} days</a>
    </p>
    <p><a href="/rowers/sessions/coach/?startdate={{ timeperiod|nextperiodstart }}&enddate={{ timeperiod|nextperiodend}}">Forward by
        {{ timeperiod|timedeltadays }} days</a>
    </p>
  </li>
  <li class="grid_4">


    <table width="90%" class="listtable">
      <thead>
        <tr>
          <th align="left">On or after</th>
          <th align="left">On or before</th>
          <th align="left">Preferred date</th>
          <th align="left">Name</th>
          {% for r in rowers %}
          <th class="rotate"><div><span>
                {{ r.user.first_name }} {{ r.user.last_name }}
          </span></div></th>
          {% endfor %}
        </tr>
      </thead>
      <tbody>
        {% for thedict in statusdict %}
        <tr>
          <td>
            {{ thedict|lookup:'startdate'|date:"Y-m-d" }}
          </td>
          <td>
            {{ thedict|lookup:'enddate'|date:"Y-m-d" }}
          </td>
          <td>
            {{ thedict|lookup:'preferreddate'|date:"Y-m-d" }}
          </td>
          <td>
            <a href="/rowers/sessions/{{ thedict|lookup:"id" }}">
              {% if thedict|lookup:'name' %}
              {{ thedict|lookup:'name' }}
              {% else %}
              Unnamed Session
              {% endif %}
            </a>
          </td>
          {% for r in rowers %}
          <td>
            {% if thedict|lookup:'results'|lookup:r.id != 'not assigned' %}
            <a class="{{ thedict|lookup:'color'|lookup:r.id }} dot"
               title="{{ thedict|lookup:'results'|lookup:r.id }}"
               href="{% url 'plannedsession_view' id=thedict|lookup:"id" userid=r.user.id %}">&nbsp;</a>
            {% else %}
            &nbsp;
            {% endif %}
          </td>
          {% endfor %}
        </tr>
        {% endfor %}
      </tbody>
    </table>
    <p>
      <a href="/rowers/sessions/sendcalendar/user/{{ rower.user.id }}/?when={{ timeperiod }}">
        Get Calendar File</a>
    </p>
    {% if rower|is_coach:rowers %}
    <p>
      <a href="/rowers/sessions/coach/sendcalendar/user/{{ rower.user.id }}/?when={{ timeperiod }}">
        Send Calendar File to all rowers
      </a>
    </p>
    {% endif %}
  </li>

  {% if unmatchedworkouts %}
  <li class="grid_4">
    <h1>Workouts that are not linked to any session</h1>
    <table width="90%" class="listtable shortpadded">
      <thead>
        <tr>
          <th> Rower</th>
          <th style="width:80"> 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>
        </tr>
      </thead>
      <tbody>
        {% for workout in unmatchedworkouts %}
        <tr>
          <td> {{ workout.user.user.first_name }} {{ workout.user.user.last_name }} </td>
          <td> {{ workout.date|date:"Y-m-d" }} </td>
          <td> {{ workout.starttime|date:"H:i" }} </td>
          {% if workout.user.user == user or user == team.manager %}
          {% if workout.name != '' %}
          <td>
            <a href={% url rower.defaultlandingpage id=workout.id|encode %}>
              {{ workout.name }}
            </a>
          </td>
          {% else %}
          <td>
            <a href={% url rower.defaultlandingpage id=workout.id|encode %}>No Name
          </a></td>
          {% endif %}

          {% else %}
          {% if workout.name != '' %}
          <td><a href="/rowers/workout/{{ workout.id|encode }}/">{{ workout.name }}</a></td>
          {% else %}
          <td><a href="/rowers/workout/{{ workout.id|encode }}/">No Name</a> </td>
          {% endif %}
          {% endif %}
          <td> {{ workout.workouttype }} </td>
          <td> {{ workout.distance }}m</td>
          <td> {{ workout.duration |durationprint:"%H:%M:%S.%f" }} </td>
          <td> {{ workout.averagehr }} </td>
          <td> {{ workout.maxhr }} </td>
        </tr>
        {% endfor %}
      </tbody>
    </table>
  </li>


{% endif %}




</ul>
{% endblock %}

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