{% extends "base.html" %}

{% block preTitle %}
  Admin: Users -
{% endblock %}

{% block bodyContent %}
  {% for message in flash %}
    <div class="alert alert-info">{{ message|raw }}</div>
  {% endfor %}

  <h3>Admin: Users</h3>
  <table class="table-bordered table-striped table">
    <thead>
      <tr>
        <th>Email</th>
        <th>Created Date</th>
        <th>Admin?</th>
        <th>Remove</th>
      </tr>
    </thead>
    <tbody>
    {% for user in users %}
      <tr>
        <td>{{user.email}}</td>
        <td>{{user.created_date}}</td>
        <td>
          {% if (user.account_level === 1) %}
            <b>YES</b>
          {% else %}
            <form method="post" class="remove-user" action="/admin/make_admin">
              <input type="hidden" name="user" value="{{ user.email }}">
              <input type="hidden" name="_csrf" value="{{ csrfToken }}">
              <button type="submit" class="btn btn-link btn-small">Make Admin</button>
            </form>
          {% endif %}
        </td>
        <td>
        {% if user._id.toString() !== currentUser._id.toString() %}
          <form method="post" class="remove-user" action="/admin/remove_user">
            <input type="hidden" name="email" value="{{ user.email }}">
            <input type="hidden" name="_csrf" value="{{ csrfToken }}">
            <button type="submit" class="btn btn-danger btn-small">Remove</button>
          </form>
        {% endif %}
        </td>
      </tr>
    {% endfor %}
    </tbody>
  </table>
{% endblock %}
