{% extends "wagtailadmin/base.html" %}
{% load i18n %}

{% block titletag %}{% trans "Registered 2FA devices" %}{% endblock %}
{% block content %}
    {% trans "Two Factor Settings" as prefs_str %}
    {% include "wagtailadmin/shared/header.html" with title=prefs_str %}

    <div class="nice-padding">
        <table class="listing">
                <thead>
                    <tr>
                        <th class="name">
                            {% trans "Name" %}
                        </th>
                    </tr>
                </thead>
                <tbody>
                    {% for device in object_list %}
                        <tr>
                            <td class="title">
                                <h2>
                                    {{ device.name|default:"Default token" }}
                                </h2>
                            </td>
                            <td align="right">
                                {# Admins cannot update existing devices on another user's account. #}
                                {% if request.user.id == device.user_id %}
                                    <a href="{% url 'wagtail_2fa_device_update' pk=device.pk %}" class="button button-secondary button-small">{% trans 'Update device' %}</a>
                                {% endif %}

                                {# Admins can remove existing devices from another user's account. #}
                                <a href="{% url 'wagtail_2fa_device_remove' pk=device.pk %}" class="button button-secondary button-small no">{% trans 'Remove device' %}</a>
                            </td>
                        </tr>
                    {% empty %}

                        <tr>
                            <td colspan="2">
                                {% trans "There are no devices for this user." %}
                            </td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>

        {# Users can only add devices to their own account #}
        {% if user_id == request.user.id %}
            <a href="{% url 'wagtail_2fa_device_new' %}" class="button bicolor icon icon-plus">{% trans 'New device' %}</a>
        {% endif %}
    </div>
{% endblock %}
