{% extends "newbase.html" %}

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

{% block main %}
<h1>{{ team.name }}</h1>

<ul class="main-content">
  <li>
    <p>{{ team.notes }}</p>
    <p><b>Manager:</b> {{ team.manager.first_name }} {{ team.manager.last_name }}</p>
  </li>
  <li>

    {% if hasrequested %}
    <p>You have requested access to this team</p>
    {% elif team not in myteams and team not in memberteams %}
    <p>You can request access to this team. By requesting access, you
      agree to the <a href="/rowers/legal/">Privacy Policy</a> regarding
      team functionality. You agree to share your workout data (except
      workouts marked as "private") to all team members and the team manager.
      You also grant the team manager access to your heart rate and power
      zone settings, as well as your functional threshold information. You
      are granting the team manager permission to edit your workouts.</p>
    <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>
    {% endif %}
  </li>
  <li class="grid_2">
    <h2>Members</h2>
    <table width="100%" class="listtable">
      <thead>
        <tr>
          <th>Name</th>
          <th>&nbsp;</th>
        </tr>
      </thead>
      <tbody>
        {% for member in members %}
        <tr>
          {% if team.manager == user %}
          <td><a href="/rowers/me/preferences/user/{{ member.user.id }}/"> {{ member.user.first_name }} {{ member.user.last_name }}</a></td>
          <td><a class="button red small" href="/rowers/me/team/{{ team.id }}/drop/{{ member.user.id }}/">Drop</a></td>
          {% else %}
          <td>{{ member.user.first_name }} {{ member.user.last_name }}</td>
          <td>&nbsp;</td>
          {% endif %}
        </tr>
    {% endfor %}
      </tbody>
    </table>
  </li>
  <li class="grid_2">
    <h2>Group Workouts and Planned Sessions</h2>
    <p>  <a href="/rowers/list-workouts/team/{{ team.id }}/">Member workouts</a></p>
    <p> <a href="/rowers/sessions/coach/">Group Training Plan</a></p>
  </li>
  <li class="grid_2">

    {% 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 team.manager.rower.rowerplan == 'freecoach' %}
    <p>
      As a Free Coach user, your team members can only be users on a paid
      plan. You can also upgrade to a
      <a href="/rowers/paidplans/">Paid Coach Plan</a>
      which allows you to coach users on a free Rower Plan.
    </p>
    {% endif %}
    {% 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 %}
      <input type="submit" value="Submit">
    </form>
    {% else %}
    <p>
      &nbsp;
    </p>
    {% endif %}
  </li>
  <li class="grid_2">
    {% if team.manager == user %}
    <h2>Message</h2>
    <p>Use this form to send a message to all team members by email. </p>
    <form enctype="multipart/form-date" action="" method="post">
      <table>
        {{ groupmessageform.as_table }}
      </table>
      {% csrf_token %}
      <input type="submit" value="Send">
    </form>
  {% endif %}
  </li>
</ul>


{% endblock %}

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