{% extends "base.html" %}

{% block title %}Teams {% endblock %}

{% block content %}
<div class="grid_12 alpha">
  <div class="grid_6 alpha">
    <p>
      <h2>My Teams</h2>
      {% if teams %}
      <table width="70%" 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>
          <div class="grid_1">
            <a class="button small red" href="/rowers/team/{{ team.id }}/leaveconfirm">Leave</a>
          </div>
        </td>
      </tr>
      {% endfor %}
      </tbody>
      </table>
      {% else %}
    <p>You are not a member of any team.</p>
    {% endif %}
    </p>
      
    
  </div>
  <div class="grid_6 omega">
    {% if otherteams %}
    <h2>Other Teams</h2>
    <table width="70%" 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>
    
    {% else %}
    <p>&nbsp;</p>
    {% endif %}
  </div>
</div>

<div class="grid_12 alpha">
  <div class="grid_6 alpha">
    {% if user.rower.rowerplan == 'coach' %}
    <h2>Teams I manage</h2>
    <p>Number of members: {{ clubsize }}</p>
    <p>Maximum club size: {{ max_clubsize }}</p>
    {% if myteams %}
    <table width="70%" class="listtable">
      <thead>
        <tr>
          <th>Name</th>
          <th>Manager</th>
        </tr>
      </thead>
      <tbody>
        {% for team in myteams %}
        <tr>
          <td>
            <a href="/rowers/team/{{ team.id }}/">{{ team.name }}</a>
          </td>
          <td>
            <div class="grid_1">
              <a class="button small red" href="/rowers/team/{{ team.id }}/deleteconfirm">Delete</a>
            </div>
          </td>
        </tr>
        {% endfor %}
      </tbody>
    </table>
    {% endif %}
    <div class="grid_2 suffix_4 alpha">
      <a class="button green" href="/rowers/team/create">New Team</a>
    </div>
    {% else %}
    <p>&nbsp;</p>
    {% endif %}
  </div>
  <div class="grid_6 omega">
    {% if invites or requests or myrequests or myinvites %}
      <h2>Invitations and Requests</h2>
      <table width="90%" class="listtable">
        <thead>
          <tr>
            <th>Team</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>
      <div class="grid_4 alpha">
      <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>
      </div>
      
      <div id="formbutton" class="grid_1 suffix_1 omega">
        <input class="button green" type="submit" value="Submit">
      </div>
      </form>
    </p>
    {% else %}
    <p>&nbsp;</p>
    {% endif %}
  </div>
</div>


{% endblock %}
