{% extends "orga/base.html" %}
{% load bootstrap4 %}
{% load copyable %}
{% load i18n %}
{% load url_replace %}

{% block title %}{% translate "Users" %}{% endblock %}

{% block content %}
    <h2>{% translate "Users" %}</h2>

    <form>
        <input name="q" type="text" {% if request.GET.q %} value="{{ request.GET.q }}" {% endif %}>
    </form>

    <form method="post">{% csrf_token %}
        <div class="table-responsive">
            <table class="table table-sm table-hover table-flip">
                <thead>
                    <tr>
                        <th>
                            {% translate "Name" %}
                        </th>
                        <th>
                            {% translate "Email" %}
                        </th>
                        <th>
                            {{ phrases.base.language }}
                        </th>
                        <th>
                            {% translate "Teams" %}
                        </th>
                        <th>
                            {% translate "Events" %}
                        </th>
                        <th class="numeric">
                            {% translate "Submissions" %}
                        </th>
                        <th class="numeric">
                            {% translate "Last login" %}
                        </th>
                        <th class="numeric">
                            {% translate "Password reset time" %}
                        </th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                    {% for user in users %}
                        <tr>
                            <td>
                                <a href="/orga/admin/users/{{ user.code }}/">{{ user.name }}</a>
                            </td>
                            <td>{{ user.email|copyable }}</td>
                            <td>{{ user.locale }}</td>
                            <td>
                                <ul>
                                    {% for team in user.teams.all %}
                                        <li><a href="{{ team.urls.base }}">{{ team.name }}</li>
                                    {% endfor %}
                                </ul>
                            </td>
                            <td>
                                <ul>
                                    {% for event in user.get_events_with_any_permission %}
                                        <li><a href="{{ event.orga_urls.base }}">{{ event.name }}</li>
                                    {% endfor %}
                                </ul>
                            </td>
                            <td class="numeric">{{ user.submission_count }}</td>
                            <td class="numeric-left">{{ user.last_login|timesince }} {% if user.last_login %}ago{% endif %}</td>
                            <td class="numeric-left">{{ user.pw_reset_time|timesince }}{% if user.pw_reset_time %} ago{% endif %}</td>
                            <td>
                                <div class="d-flex mb-2">
                                    <a href="/orga/admin/users/{{ user.code }}/" class="btn btn-xs btn-info mr-2"> <i class="fa fa-edit"></i> </a>
                                    <button name="action" value="delete-{{ user.id }}" class="btn btn-xs btn-danger"><i class="fa fa-trash"></i></button>
                                </div>
                                <button name="action" value="reset-{{ user.id }}" class="btn btn-xs btn-warning mr-2">{{ phrases.base.password_reset_heading }}</button>
                            </td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        </form>
    </div>
    {% include "orga/includes/pagination.html" %}
{% endblock %}


