{% extends "base.html" %}

{% block title %}Team {% endblock %}

{% block content %}
  <div class="grid_12 alpha">
    {% include "teambuttons.html" with teamid=team.id %}
  </div>
  <div class="grid_12">
    <div class="grid_8 alpha">
  <h1>{{ team.name }}</h1>

  <div class="grid_4 omega">
    <p>{{ team.notes }}</p>
    <p><b>Manager:</b> {{ team.manager.first_name }} {{ team.manager.last_name }}</p>
  </div>
</div>
<div class="grid_12 alpha">
  {% if ismember %}
  <div class="grid_2 alpha">
    <a class="button red small" href="/rowers/team/{{ team.id }}/leaveconfirm">Leave this team</a>
  </div>
  {% if team.manager == user %}
  <div class="grid_2 suffix_8 omega">
    <a class="button blue small" href="/rowers/team/{{ team.id }}/edit">Edit Team</a>
  </div>
  {% else %}
  <div class="grid_2 suffix_8 omega">
    <p>&nbsp;
  </div>
  {% endif %}
  {% elif hasrequested %}
  <p>You have requested access to this team</p>
  {% else %}
  <div class="grid_2 suffix_10 alpha tooltip">
    <a class="button green small" href="/rowers/team/{{ team.id }}/requestmembership/{{ user.id }}">Join</a>
    <span class="tooltiptext">A request will be sent to the team manager</span>
      
  </div>
  {% endif %}
</div>

<div class="grid_12 alpha">
  <div class="grid_6 alpha">
    <p>
      <h2>Members</h2>
      <table width="70%" class="listtable">
        <thead>
          <tr>
            <th>Name</th>
            <th>&nbsp;</th>
          </tr>
        </thead>
        <tbody>
      {% for member in members %}
      <tr>
        <td> {{ member.user.first_name }} {{ member.user.last_name }}</td>
        {% if team.manager == user %}
        <td><a class="button red small" href="/rowers/me/team/{{ team.id }}/drop/{{ member.user.id }}">Drop</a></td>
        {% else %}
        <td>&nbsp;</td>
        {% endif %}
      </tr>
      {% endfor %}
      </tbody>
      </table>
    </p>
    
    
  </div>
  <div class="grid_6 omega">
    {% if team.manager == user %}
    <p>Use the form to add a new user. You can either select a user from the list of your existing club members who are not on this team yet, or you can type the user's email address, which also works for users who have not registered to the site yet.</p>
    {% if inviteform.errors %}
    <p style="color: red;">
      Please correct the error{{ inviteform.errors|pluralize }} below.
    </p>
    {% endif %}
    <form enctype="multipart/form-data" action="{{ formloc }}" method="post">
      <table>
        {{ inviteform.as_table }}
      </table>
      {% csrf_token %}
      <div id="formbutton" class="grid_1 prefix_4 suffix_1">
        <input class="button green" type="submit" value="Submit">
      </div>
    </form>
    {% else %}
    <p>
      &nbsp;
    </p>
    {% endif %}
  </div>
</div>
</div>



{% endblock %}
