{% extends "newbase.html" %}

{% block title %}Groups {% endblock %}

{% block main %}
<ul class="main-content">
  {% if teams %}
  <li class="grid_2">
    <h2>My Groups</h2>
    <table width="100%" class="listtable">
      <thead>
        <tr>
          <th>Name</th>
          <th>&nbsp;</th>
        </tr>
      </thead>
      <tbody>
      {% for team in teams %}
      <tr>
        <td>
          <a href="/rowers/team/{{ team.id }}/">{{ team.name }}</a>
        </td>
        <td>
          <a class="button small red" href="/rowers/team/{{ team.id }}/leaveconfirm/">Leave</a>
        </td>
      </tr>
      {% endfor %}
      </tbody>
    </table>
  </li>
  {% endif %}
    
  {% if otherteams %}
  <li  class="grid_2">
    <h2>Open Groups</h2>
    <table width="100%" class="listtable">
      <thead>
        <tr>
          <th>Name</th>
          <th>Manager</th>
        </tr>
      </thead>
      <tbody>
        {% for team in otherteams %}
        <tr>
          <td>
            <a href="/rowers/team/{{ team.id }}/">{{ team.name }}</a>
          </td>
          <td>
            {{ team.manager.first_name }} {{ team.manager.last_name }}
          </td>
        </tr>
        {% endfor %}
      </tbody>
    </table>
  </li>
  {% endif %}

  <li  class="grid_2">
    <h2>Groups I manage</h2>
    {% if myteams %}
    <table width="100%" class="listtable">
      <thead>
        <tr>
          <th>Name</th>
          <th>&nbsp;</th>
        </tr>
      </thead>
      <tbody>
        {% for team in myteams %}
        <tr>
          <td>
            <a href="/rowers/team/{{ team.id }}/">{{ team.name }}</a>
          </td>
          <td>
            <a class="button small red" href="/rowers/team/{{ team.id }}/deleteconfirm/">Delete</a>
          </td>
        </tr>
        {% endfor %}
      </tbody>
    </table>
    {% endif %}
    <a href="/rowers/team/create/">Create New Training Group</a>
  </li>
  {% if coaches %}
  <li  class="grid_2">
    <h2>My Coaches</h2>
    <table width="100%" class="listtable">
      <thead>
	<tr>
	  <th>Coach</th>
	</tr>
      </thead>
      <tbody>
	{% for coach in coaches %}
	<tr>
	  <td>
	    {{ coach.user.first_name }} {{ coach.user.last_name }}
	  </td>
	  <td>
	    <a class="button small red"
	       href="/rowers/coaches/{{ coach.id }}/dropcoachconfirm/">Remove
	    </a>
	  </td>
	</tr>
	{% endfor %}
      </tbody>
    </table>
  </li>
  {% endif %}
  {% if coachees %}
  <li class="grid_2">
    <h2>My Rowers</h2>
    <table width="100%" class="listtable">
      <thead>
	<tr>
	  <th>Name</th>
	</tr>
      </thead>
      <tbody>
	{% for coachee in coachees %}
	<tr>
	  <td>
	    {{ coachee.user.first_name }} {{ coachee.user.last_name }}
	  </td>
	  <td>
	    <a class="button small red"
	       href="/rowers/coaches/{{ coachee.id }}/dropconfirm/">Remove
	    </a>
	  </td>
	</tr>
	{% endfor %}
      </tbody>
    </table>
  </li>
  {% endif %}
  {% if invites or requests or myrequests or myinvites %}
  <li class="grid_2">
    <h2>Group Invitations and Requests</h2>
    <p>This section lists open invites to join a group. By accepting
      a group invite, you are agreeing with the sharing 
      of personal data between group members and coaches according to
      our <a href="/rowers/legal/">privacy policy</a>.
    </p>
    
    <p>As a group manager, by accepting a group invite, you are agreeing
      with our <a href="/rowers/legal/">privacy policy</a> regarding groups and
      personal data owned by group members.</p>

      <table width="90%" class="listtable">
        <thead>
          <tr>
            <th>Group</th>
            <th>Manager</th>
            <th>User</th>
            <th>Action</th>
            <th>&nbsp;</th>
          </tr>
        </thead>
        <tbody>
          {% for i in invites %}
          <tr>
            <td><a href="/rowers/team/{{ i.team.id }}/">{{ i.team.name }}</a></td>
            <td>{{ i.team.manager.first_name }} {{ i.team.manager.last_name }}</td>
            <td>{{ user.first_name }} {{ user.last_name }}</td>
            <td><a class="button small green" href="/rowers/me/invitation/{{ i.code }}/">Accept</a>
            </td>
            <td>
              <a class="button small red" href="/rowers/me/invitation/{{ i.id }}/reject/">Reject</a>
            </td>
          </tr>
          {% endfor %}
          {% for i in requests %}
          <tr>
            <td><a href="/rowers/team/{{ i.team.id }}/">{{ i.team.name }}</a></td>
            <td>{{ i.team.manager.first_name }} {{ i.team.manager.last_name }}</td>
            <td>{{ user.first_name }} {{ user.last_name }}</td>
            <td></td>
            <td><a class="button red small" href="/rowers/me/request/{{ i.id }}/revoke/">Revoke</a>
          </tr>
          {% endfor %}
          {% for i in myrequests %}
          <tr>
            <td><a href="/rowers/team/{{ i.team.id }}/">{{ i.team.name }}</a></td>
            <td>{{ i.team.manager.first_name }} {{ i.team.manager.last_name }}</td>
            <td>{{ i.user.first_name }} {{ i.user.last_name }}</td>
            <td><a class="button small green" href="/rowers/me/request/{{ i.code }}/">Accept</a>
            <td>
              <a class="button small red" href="/rowers/me/request/{{ i.id }}/reject/">Reject</a>
            </td>
          </tr>
          {% endfor %}
          {% for i in myinvites %}
          <tr>
            <td><a href="/rowers/team/{{ i.team.id }}/">{{ i.team.name }}</a></td>
            <td>{{ i.team.manager.first_name }} {{ i.team.manager.last_name }}</td>
            {% if i.user %}
            <td>{{ i.user.first_name }} {{ i.user.last_name }}</td>
            {% else %}
            <td>{{ i.email }}</td>
            {% endif %}
            <td>&nbsp;
            <td>
              <a class="button small red" href="/rowers/me/invitation/{{ i.id }}/revoke/">Revoke</a>
            </td>
          </tr>
          {% endfor %}
        </tbody>
      </table>
      <h3>Manual code redeem</h3>
      <form enctype="multipart/form-data" action="{{ formloc }}" method="post">
        {% if form.errors %}
        <p style\"color: red;">
          Please correct the error{{ form.errors|pluralize }} below.
        </p>
        {% endif %}
        {% csrf_token %}
        <table>
          {{ form.as_table }}
        </table>
        <input class="button green" type="submit" value="Submit">
      </form>
    {% endif %}
  {% if mycoachrequests or mycoachoffers or coachoffers or coachrequests %}
  <li class="grid_2">
    <h2>Coaching Offers and Requests</h2>
    <p>This section lists open offers and requests related to coaching.
      By accepting a coaching offer, the coach can run
      analysis, add workouts and edit settings on behalf of the athlete. 
      You agree to the sharing
      of personal data between athletes and coaches according to
      our <a href="/rowers/legal/">privacy policy</a>.
    </p>    
      <table width="90%" class="listtable">
        <thead>
          <tr>
            <th>Coach</th>
            <th>User</th>
            <th>Action</th>
            <th>&nbsp;</th>
          </tr>
        </thead>
        <tbody>
          {% for i in coachrequests %}
          <tr>
            <td>{{ i.coach.user.first_name }} {{ i.coach.user.last_name }}</td>
            <td>{{ i.user.first_name }} {{ i.user.last_name }}</td>
            <td><a
		  class="button small green"
		  href="/rowers/me/coachrequest/{{ i.code }}/accept">Accept</a>
            </td>
            <td>
              <a class="button small red" href="/rowers/me/coachrequest/{{ i.id }}/reject/">Reject</a>
            </td>
          </tr>
          {% endfor %}
          {% for i in mycoachoffers %}
          <tr>
            <td>{{ i.coach.user.first_name }} {{ i.coach.user.last_name }}</td>
            <td>{{ i.user.first_name }} {{ i.user.last_name }}</td>
            <td>&nbsp;
            </td>
            <td>
              <a class="button small red" href="/rowers/me/coachoffer/{{ i.id }}/revoke/">Revoke</a>
            </td>
          </tr>
          {% endfor %}
          {% for i in mycoachrequests %}
          <tr>
            <td>{{ i.coach.user.first_name }} {{ i.coach.user.last_name }}</td>
            <td>{{ i.user.first_name }} {{ i.user.last_name }}</td>
	    <td>&nbsp;</td>
            <td>
              <a
		class="button small red"
		href="/rowers/me/coachrequest/{{ i.id }}/revoke/">Revoke</a>
            </td>
          </tr>
          {% endfor %}
          {% for i in coachoffers %}
          <tr>
            <td>{{ i.coach.user.first_name }} {{ i.coach.user.last_name }}</td>
            <td>{{ i.user.first_name }} {{ i.user.last_name }}</td>
	    <td><a
		  class="button small green"
		  href="/rowers/me/coachoffer/{{ i.code }}/accept/">Accept</a>
	    </td>
            <td>
              <a
		class="button small red"
		href="/rowers/me/coachoffer/{{ i.id }}/revoke/">Reject</a>
            </td>
          </tr>
          {% endfor %}
        </tbody>
      </table>
    {% endif %}
  </li>
  {% if potentialathletes %}
  <li class="grid_2">
    <h2>Rowers you could coach</h2>
      <table width="90%" class="listtable">
        <thead>
          <tr>
            <th>User</th>
            <th>Action</th>
          </tr>
        </thead>
        <tbody>
          {% for a in potentialathletes %}
          <tr>
            <td>{{ a.user.first_name }} {{ a.user.last_name }}</td>
            <td>
	      <a
		class="button small green"
		href="/rowers/me/coachoffer/{{ a.user.id }}/">Offer Coaching</a>
            </td>
          </tr>
          {% endfor %}
        </tbody>
      </table>
  </li>  
  {% endif %}
  {% if potentialcoaches %}
  <li class="grid_2">
    <h2>Coaches who could coach you</h2>
      <table width="90%" class="listtable">
        <thead>
          <tr>
            <th>User</th>
            <th>Action</th>
          </tr>
        </thead>
        <tbody>
          {% for c in potentialcoaches %}
          <tr>
            <td>{{ c.first_name }} {{ c.last_name }}</td>
            <td>
	      <a
		class="button small green"
		href="/rowers/me/coachrequest/{{ c.id }}/">Request Coaching</a>
            </td>
          </tr>
          {% endfor %}
        </tbody>
      </table>
  </li>
  {% endif %}
</ul>


{% endblock %}

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