{% 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_6 alpha">
  <h1>Plan for {{ rower.user.first_name }} {{ rower.user.last_name }}</h1>
</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/today/rower/{{ rower.id }}">
      Today
    </a>
    <a class="button gray small alpha"
       href="/rowers/sessions/thisweek/rower/{{ rower.id }}">
      This Week
    </a>
    <a class="button gray small alpha"
       href="/rowers/sessions/thismonth/rower/{{ rower.id }}">
      This Month
    </a>
    <a class="button gray small alpha"
       href="/rowers/sessions/lastweek/rower/{{ rower.id }}">
      Last Week
    </a>
    <a class="button gray small alpha"
       href="/rowers/sessions/lastmonth/rower/{{ rower.id }}">
      Last Month
    </a>
    <a class="button gray small alpha"
       href="/rowers/sessions/nextweek/rower/{{ rower.id }}">
      Next Week
    </a>
    <a class="button gray small alpha"
       href="/rowers/sessions/nextmonth/rower/{{ rower.id }}">
      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">
    {{ rower.user.first_name }} {{ rower.user.last_name }}
  </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>
{% endif %}
<div class="grid_2 omega">
  <a class="button small gray" href="/rowers/list-courses">Courses</a>
</div>
<div class="grid_12 alpha">
  {% if plannedsessions %}
  <p>
    Click on session name to view, edit to change the session and on the
    traffic light symbol to add workouts to the session
  </p>
  <table width="90%" class="listtable shortpadded">
    <thead>
      <tr>
        <th>Status</th>
        <th>On or After</th>
        <th>On or Before</th>
        <th>Name</th>
        <th>Type</th>
        <th>Mode</th>
        <th>Edit</th>
        <th>Planned</th>
        <th>Actual</th>
        <th>&nbsp;</th>
        <th>Completion Date</th>
        <th>
      </tr>
    </thead>
    <tbody>
      {% for ps in plannedsessions %}
      <tr>
        <td>
          {% if completeness|lookup:ps.id == 'not done' %}
          {% if ps.sessiontype != 'race' %}
          <a class="white dot" href="/rowers/sessions/manage/{{ timeperiod }}/rower/{{ rower.id }}/session/{{ ps.id }}">&nbsp;</a>
          {% else %}
          <a class="white dot" href="/rowers/virtualevent/{{ ps.id }}/submit">&nbsp;</a>
          {% endif %}
          {% elif completeness|lookup:ps.id == 'completed' %}
          {% if ps.sessiontype != 'race' %}
          <a class="green dot" href="/rowers/sessions/manage/{{ timeperiod }}/rower/{{ rower.id }}/session/{{ ps.id }}">&nbsp;</a>
          {% else %}
          <a class="green dot" href="/rowers/virtualevent/{{ ps.id }}/submit">&nbsp;</a>
          {% endif %}
          {% elif completeness|lookup:ps.id == 'partial' %}
          {% if ps.sessiontype != 'race' %}
          <a class="orange dot" href="/rowers/sessions/manage/{{ timeperiod }}/rower/{{ rower.id }}/session/{{ ps.id }}">&nbsp;</a>
          {% else %}
          <a class="orange dot" href="/rowers/virtualevent/{{ ps.id }}/submit">&nbsp;</a>
          {% endif %}
          {% else %}
          {% if ps.sessiontype != 'race' %}
          <a class="red dot" href="/rowers/sessions/manage/{{ timeperiod }}/rower/{{ rower.id }}/session/{{ ps.id }}">&nbsp;</a>
          {% else %}
          <a class="red dot" href="/rowers/virtualevent/{{ ps.id }}/submit">&nbsp;</a>
          {% endif %}
          {% endif %}
        </td>
        <td> {{ ps.startdate|date:"Y-m-d" }} </td>
        <td> {{ ps.enddate|date:"Y-m-d" }} </td>
        <td>
          {% if ps.sessiontype != 'race' %}
          {% if ps.name != '' %}
          <a class="small"
             href="/rowers/sessions/{{ ps.id }}/{{ timeperiod }}/rower/{{ rower.id }}">{{ ps.name }}</a>
          {% else %}
          <a class="small"
             href="/rowers/sessions/{{ ps.id }}/{{ timeperiod }}/rower/{{ rower.id }}">Unnamed Session</a>
          {% endif %}
          {% else %}
          {% if ps.name != '' %}
          <a class="small"
             href="/rowers/virtualevent/{{ ps.id }}">{{ ps.name }}</a>
          {% else %}
          <a class="small"
             href="/rowers/virtualevent/{{ ps.id }}">Unnamed Race</a>
          {% endif %}
          {% endif %}
        </td>
        <td> {{ ps.get_sessiontype_display }} </td>
        <td> {{ ps.get_sessionmode_display }} </td>
        <td>
          {% if ps.manager == request.user %}
          <a class="small"
             href="/rowers/sessions/{{ ps.id }}/edit/{{ timeperiod }}/rower/{{ rower.id }} ">Edit</a>
            {% else %}
          &nbsp;
          {% endif %}
        </td>
        <td> {{ ps.sessionvalue }} </td>
        <td> {{ actualvalue|lookup:ps.id }}</td>
        <td> {{ ps.sessionunit }} </td>
        {% if completeness|lookup:ps.id == 'partial' %}
        <td style="color:darkgray"><i> {{ completiondate|lookup:ps.id|date:"Y-m-d" }}</i></td>
        {% else %}
        <td> {{ completiondate|lookup:ps.id|date:"Y-m-d" }}</td>
        {% endif %}
      </tr>
      {% endfor %}
    </tbody>
  </table>
  {% else %}
  You have no planned workouts for this period. Planned workouts are created
  by your coach if you are part of a team. You can create your own
  planned workouts by purchasing the "Coach" or "Self-Coach" plans.
  {% endif %}
  <p>
    <a class="grid_2 button gray" href="/rowers/sessions/print/{{ timeperiod }}/rower/{{ rower.id }}">Print View</a>
  <p>
  {% if unmatchedworkouts %}
  <h1>Workouts that are not linked to any session</h1>
  <table width="90%" class="listtable shortpadded">
    <thead>
      <tr>
          <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.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 %}
