{% extends 'base.html' %}

{% block content %}
<div class="container-fluid mt-0">
    <h1>{{ _("Users") }}</h1>
    <h3>{{ _("List of machines and web interface users") }}</h3>
    <a href="{{ url_for('add_user') }}" class="btn btn-primary mb-3">{{ _("Add User...") }}</a>
    <table class="table table-striped">
        <thead>
            <tr>
                <th>{{ _("ID") }}</th>
                <th>{{ _("Name") }}</th>
                <th>{{ _("Surname") }}</th>
                <th>{{ _("Role") }}</th>
                <th class="d-none d-lg-table-cell">{{ _("Card UUID") }}</th>
                <th class="d-none d-lg-table-cell">{{ _("Email") }}</th>
                <th class="d-none d-lg-table-cell">{{ _("Disabled?") }}</th>
                <th>{{ _("Action") }}</th>
            </tr>
        </thead>
        <tbody>
            {% for user in users %}
            <tr>
                <td>{{ user.user_id }}</td>
                <td>{{ user.name }}</td>
                <td>{{ user.surname }}</td>
                <td>
                    <span class="badge bg-dark">{{ user.role.role_name }}</span>
                </td>
                <td class="d-none d-lg-table-cell">{{ user.card_UUID }}</td>
                <td class="d-none d-lg-table-cell">
                    {% if user.email != "" %}
                    <a href="mailto:{{ user.email }}">{{ user.email }}</a><br />
                    {% endif %}
                </td>
                <td class="d-none d-lg-table-cell">
                    {% if user.disabled %}
                    <i class="fa fa-lock" aria-hidden="true"></i>
                    {% else %}
                    <i class="fa fa-unlock" aria-hidden="true"></i>
                    {% endif %}
                </td>
                <td>
                    <a href="{{ url_for('edit_user', user_id=user.user_id) }}" class="btn btn-warning">{{ _("Edit") }}</a>
                    <a href="{{ url_for('delete_user', user_id=user.user_id) }}" class="btn btn-danger">{{ _("Delete") }}</a>
                    {% if user.email != "" %}
                    <a href="{{ url_for('reset_user', user_id=user.user_id) }}" class="btn btn-dark" style="margin: 15px;">{{ _("Password reset") }}</a>
                    {% endif %}
                </td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
</div>
<a href="{{ url_for('users_export') }}" class="link-info"><i class="fas fa-file-excel"></i>Export table</a>
<div class="container-fluid mt-0">
    <h3>{{ _("List of last 20 rejected RFID cards") }}</h3>
    <table class="table table-striped">
        <thead>
            <tr>
                <th>{{ _("Machine") }}</th>
                <th>{{ _("Card UUID") }}</th>
                <th>{{ _("Time of attempt") }}</th>
                <th>{{ _("Action") }}</th>
            </tr>
        </thead>
        <tbody>
            {% for card in cards %}
            <tr>
                <td>{{ card.machine.machine_name }}</td>
                <td>{{ card.card_UUID }}</td>
                <td>{{ card.timestamp|time_since }}</td>
                <td>
                    <a href="{{ url_for('add_user', card_uuid = card.card_UUID) }}" class="btn btn-warning">{{ _("Convert to new user") }}</a>
                </td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
</div>
{% endblock %}