{% extends "admin/base.html" %}

{% load i18n %}

{% block title %}{% trans "Authentication Tokens" %}{% endblock %}

{% block content %}
    <div class="text-left">
        <h3>{% trans "Authentication Tokens" %}</h3>
    </div>
    <form action="{% url 'core:tokens' %}" method="post">
      {% csrf_token %}
        <div class="col-12 p-3">
            {% if has_perm_add_authtoken %}
              <a href="{% url 'core:token' %}" class="btn btn-success"  role="button">{% trans "New API Token" %}</a>
            {% else %}
              <a href="#" class="btn btn-secondary disabled"  role="button">{% trans "New API Token" %}</a>
            {% endif %}
            
              <select name="action" required="">
                <option value="" selected="">---------</option>
                <option value="delete_selected">Delete selected auth tokens</option>
              </select>
            <button class="btn btn-outline-dark mx-1" type="submit">{% trans "Go" %}</button>
        </div>
        <div class="col-12 p-3">
          {% if tokens|length > 0 %}          
            <table class="table table-striped">
              <thead class="thead-dark">
                <tr>
                  <th>
                      <div id="checkbox_view">
                        <span class="mr-2"><input type="checkbox" id="action_toggle"></span>{% trans "Digest" %}
                      </div>
                  </th>
                  <th>{% trans "Created At" %}</th>
                  <th>{% trans "Expires At" %}</th>
                </tr>
              </thead>
              <tbody>
                {% for token in tokens %}
                  <tr>
                    <td><span class="mr-2"><input type="checkbox" name="_selected_action" value="{{ token.digest }}" /></span>{{ token.digest|truncatechars:24 }}</td>
                    <td>{{ token.created }}</td>
                    <td>{{ token.expiry }}</td>
                  </tr>
                {% endfor %}
              </tbody>
            </table>
          {% else %}
              {% trans "No API Tokens defined so far" %}
          {% endif %}
      </div>
    </form>
{% endblock %}