{% extends "base.html" %}
{% import "macros.html" as macros %}

{% block content %}
{% for permission in ('submit', 'review', 'pay') %}
<div class="row" id="{{ permission }}">
  <div class="col-md-12">
    {% if permission == 'submit' %}
    <h2>Submitters</h2>
    {% elif permission == 'review' %}
    <h2>Reviewers</h2>
    {% elif permission == 'pay' %}
    <h2>Payers</h2>
    {% endif %}
  </div>
  <div class="col-md-8">
    <table class="table table-condensed">
      <tr>
        <th>Name</th>
        <th>Type</th>
        <th>Authentication Source</th>
        <th>Remove</th>
      </tr>
      {% for entity in division.permissions[permission]|map(attribute='entity') %}
      <tr>
        <td>{{ entity.name }}</td>
        {% if entity.users is defined %}
        <td>Group ({{ entity.users|length }})</td>
        {% else %}
        <td>User</td>
        {% endif %}
        <td>{{ entity.authmethod().name }}</td>
        <td>
          <form method="post">
            {{ entity_form.csrf_token() }}
            {{ entity_form.id_(value=entity.id) }}
            {{ entity_form.permission(value=permission) }}
            {{ entity_form.action(value='delete') }}
            {{ entity_form.form_id }}
            <button class="close" type="submit">&times;</button>
          </form>
        </td>
      </tr>
      {% endfor %}
    </table>
  </div>
  <div class="col-md-4">
    <form class="form-horizontal" role="form" method="post" autocomplete="off">
      <div class="form-group">
        <label class="col-md-2 control-label" for="add-{{ permission }}-name">Name</label>
        <div class="col-md-10">
          <input type="text" class="form-control entity-typeahead typeahead" id="add-{{ permission }}-name" name="name" autocomplete="off" placeholder="Name">
        </div>
      </div>
      <div class="form-group">
        <div class="col-md-offset-2 col-md-10">
          <button type="submit" class="btn btn-default">Add {{ entity|capitalize }}</button>
        </div>
      </div>
      {{ entity_form.csrf_token() }}
      {{ entity_form.action(value="add") }}
      {{ entity_form.permission(value=permission) }}
      {{ entity_form.id_() }}
      {{ entity_form.form_id }}
    </form>
  </div>
</div>
{% endfor %}
<div class="row">
  <div class="col-md-6">
    <h2>Ship URL Transformer</h2>
    <form method="post">
      {{ ship_form.form_id }}
      {{ ship_form.kind(value='ship') }}
      {{ ship_form.csrf_token }}
      {{ macros.render_input(ship_form.name) }}
      <button type="submit" class="btn btn-default">Save</button>
    </form>
  </div>
  <div class="col-md-6">
    <h2>Pilot URL Transformer</h2>
    <form method="post">
      {{ pilot_form.form_id }}
      {{ pilot_form.kind(value='pilot') }}
      {{ pilot_form.csrf_token }}
      {{ macros.render_input(pilot_form.name) }}
      <button type="submit" class="btn btn-default">Save</button>
    </form>
  </div>
</div>
{% endblock content %}
