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

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

{% block content %}
<div class="grid_12 alpha">
  {% include "planningbuttons.html" %}
</div>
<div class="grid_4 alpha">
  {% if theteam %}
  <h1>Coach Overview. Team {{ theteam.name }}</h1>
  {% else %}
  <h1>Coach Overview</h1>
  {% endif %}
</div>
<div id="timeperiod" class="grid_2 dropdown">
  <button class="grid_2 alpha button gray small dropbtn">Select Time Period ({{ timeperiod|verbosetimeperiod }})</button>
  <div class="dropdown-content">
    <a class="button gray small alpha"
       href="/rowers/sessions/coach/today">
      Today
    </a>
    <a class="button gray small alpha"
       href="/rowers/sessions/coach/thisweek">
      This Week
    </a>
    <a class="button gray small alpha"
       href="/rowers/sessions/coach/thismonth">
      This Month
    </a>
    <a class="button gray small alpha"
       href="/rowers/sessions/coach/lastweek">
      Last Week
    </a>
    <a class="button gray small alpha"
       href="/rowers/sessions/coach/lastmonth">
      Last Month
    </a>
    <a class="button gray small alpha"
       href="/rowers/sessions/coach/nextweek">
      Next Week
    </a>
    <a class="button gray small alpha"
       href="/rowers/sessions/coach/nextmonth">
      Next Month
    </a>
  </div>
</div>
{% if user.is_authenticated and user|is_manager %}
<div class="grid_2 dropdown">
  <button class="grid_2 alpha button green small dropbtn">
    Select Rower Individual Plan
  </button>
  <div class="dropdown-content">
    {% for member in user|team_rowers %}
    <a class="button green small" href="/rowers/sessions/{{ timeperiod }}/rower/{{ member.id }}">{{ member.user.first_name }} {{ member.user.last_name }}</a>
    {% endfor %}
  </div>
</div>
<div class="grid_2 dropdown">
  <button class="grid_2 alpha button green small dropbtn">
    Select Team
  </button>
  <div class="dropdown-content">
    <a class="button green small" href="/rowers/sessions/coach/{{ timeperiod }}">
      All Teams
    </a>
    
    {% for team in myteams %}
    <a class="button green small" href="/rowers/sessions/coach/{{ timeperiod }}/team/{{ team.id }}">{{ team.name }}</a>
    {% endfor %}
  </div>
</div>
{% endif %}

<div class="grid_12 alpha">
  <table width="90%" class="listtable">
    <thead>
      <tr>
        <th>On or after</th>
        <th>On or before</th>
        <th>Preferred date</th>
        <th>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 == 'completed' %}
          <a class="green dot"
             href="{% url 'plannedsession_view' id=thedict|lookup:"id" rowerid=r.id %}">&nbsp;</a>
          {% elif thedict|lookup:'results'|lookup:r.id == 'partial' %}
          <a class="orange dot"
             href="{% url 'plannedsession_view' id=thedict|lookup:"id" rowerid=r.id %}">&nbsp;</a>
          {% elif thedict|lookup:'results'|lookup:r.id == 'not done' %}
          <a class="white dot"
             href="/rowers/sessions/manage/{{ timeperiod }}/rower/{{ r.id }}/session/{{ thedict|lookup:"id" }}">&nbsp;</a>
          {% elif thedict|lookup:'results'|lookup:r.id == 'not assigned' %}
          &nbsp;
          {% else %}
          <a class="red dot"
             href="/rowers/sessions/manage/{{ timeperiod }}/rower/{{ r.id }}/session/{{ thedict|lookup:"id" }}">&nbsp;</a>
          {% endif %}
        </td>
        {% endfor %}
      </tr>
      {% endfor %}  
    </tbody>
  </table>

  {% if unmatchedworkouts %}
  <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 %}>
            {{ workout.name }}
          </a>
        </td>
        {% else %}
        <td>
          <a href={% url rower.defaultlandingpage id=workout.id %}>No Name
        </a></td> 
        {% endif %}
        {% else %}
        {% if workout.name != '' %}
        <td><a href="/rowers/workout/{{ workout.id }}/">{{ workout.name }}</a></td>
        {% else %}
        <td><a href="/rowers/workout/{{ workout.id }}/">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>

  
  {% endif %}

</div>
  


</form>
{% endblock %}
