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

{% block meta %}
{% endblock %}

{% block title %}Planned Session{% endblock %}

{% block content %}

<div class="grid_12 alpha">
  {% include "planningbuttons.html" %}

</div>
<div class="grid_12 alpha">
  <div class="grid_2 alpha">
  {% if user.is_authenticated and psdict.id.1|is_session_manager:user %}
  <a class="button small gray" href="/rowers/sessions/{{ psdict.id.1 }}/edit/rower/{{ rower.id }}">
    Edit Session</a>
  {% else %}
  &nbsp;
  {% endif %}
  </div>
  <div class="grid_2">
    {% if plannedsession.sessiontype == 'coursetest' %}
    <a class="button small gray" href="/rowers/list-courses">Courses</a>
    {% else %}
    &nbsp;
    {% endif %}
  </div>
</div>
<div class="grid_12 alpha">
<div id="left" class="grid_6 alpha">
  <h1>Session {{ psdict.name.1 }}</h1>
  <table class="listtable shortpadded" width="95%">
    {% for attr in attrs %}
    {% for key,value in psdict.items %}
    {% if key == attr %}
    <tr>
      {% if key == 'comment' %}
      <td><b>{{ value.0 }}</b></td><td class="wrapwords">{{ value.1|linebreaks }}</td>
      {% else %}
      <td><b>{{ value.0 }}</b></td><td class="wrapwords">{{ value.1 }}</td>
      {% endif %}
    </tr>
    {% endif %}
    {% endfor %}
    {% endfor %}
  </table>
</div>
<div id="right" class="grid_6 omega">
  {% if plannedsession.sessiontype == 'test' or plannedsession.sessiontype == 'coursetest' %}
  <h1>Ranking</h1>
  <table id="rankingtable" class="listtable shortpadded tablesorter" width="80%">
    <thead>
      <tr>
        <th>Nr</th>
        <th>Name</th>
        <th>Distance</th>
        <th>Time</th>
        <th>Date</th>
        <th>Type</th>
      </tr>
    </thead>
    <tbody>
      {% for result in ranking %}
      <tr>
        <td>{{ forloop.counter }}</td>
        <td>{{ result|lookup:'name' }}</td>
        <td>{{ result|lookup:'distance' }}</td>
        <td>{{ result|lookup:'time'|deltatimeprint }}</td>
        <td>{{ result|lookup:'date'|date:"Y-m-d" }}</td>
        <td>{{ result|lookup:'type' }}</td>
      </tr>
      {% endfor %}
    </tbody>
  </table>
  {% endif %}
  <h1>Workouts attached</h1>
  <table class="listtable shortpadded" width="80%">
    <thead>
      <tr>
        <th>Date</th>
        <th>Name</th>
        <th>Distance</th>
        <th>Duration</th>
      </tr>
    </thead>
    <tbody>
    {% for workout in workouts %}
    <tr>
          <td> {{ workout.date|date:"Y-m-d" }} </td>
          <td>
            <div class="tooltip">
            <a href={% url manager.defaultlandingpage id=workout.id %}>
              {{ workout.name }}
            </a>
            <span class="tooltiptext">{{ workout.notes }}</span>
            </div>
          </td>
          <td> {{ workout.distance }}m</td>
          <td> {{ workout.duration |durationprint:"%H:%M:%S.%f" }} </td>      
    </tr>
    {% endfor %}
    </tbody>
  </table>
</div>
</div>
<div class="grid_12 alpha">
<div id="left" class="grid_6 alpha">
  <h1>{{ rower.user.first_name }} {{ rower.user.last_name }}</h1>
  <p>Status: {{ status }}</p>
  <p>Percentage complete: {{ ratio }} </p>
</div>
<div id="right" class="grid_6 omega">
  <h1>Stats</h1>
  <table class="listtable shortpadded" width="100%">
    <thead>
      <tr>
        <th>Name</th>
        <th>Minutes</th>
        <th>Meters</th>
        <th>rScore</th>
        <th>TRIMP</th>
        <th>Complete Date</th>
        <th>Status</th>
      </tr>
    </thead>
    <tbody>
      {% for id, value in results.items %}
      <tr>
        <td>{{ value|lookup:'first_name' }} {{ value|lookup:'last_name' }}</td>
        <td>{{ value|lookup:'duration' }}</td>
        <td>{{ value|lookup:'distance' }}</td>
        <td>{{ value|lookup:'rscore' }}</td>
        <td>{{ value|lookup:'trimp' }}</td>
        <td>{{ value|lookup:'completedate' }}</td>
        <td>{{ value|lookup:'status' }}</td>
      </tr>
      {% endfor %}
    </tbody>
  </table>
</div>
<div class="grid_12 alpha">
  <div id="left" class="grid_6 alpha">
    {% if coursescript %}
    <h1>Course</h1>
    {{ coursediv|safe }}

    {{ coursescript|safe }}
    {% endif %}
  </div>

</div>


{% endblock %}

{% block scripts %}
<script type="text/javascript" src="/static/admin/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/admin/js/jquery.tablesorter.min.js"></script>

<script type="text/javascript" src="/static/admin/js/jquery.tablesorter.widgets.js"></script>
<script>
  $( document ).ready(function() {
  $("#rankingtable").tablesorter();
  });
</script>

{% endblock %}
