{% extends 'base.html' %}
{% block content %}
    <h1>{{ _("Authorizations") }}</h1>
    <a href="{{ url_for('add_authorization') }}" class="btn btn-primary">{{ _("Add Authorization...") }}</a>
    <a href="{{ url_for('bulkadd_authorizations') }}" class="btn btn-warning">{{ _("Add in bulk...") }}</a>
    <form method="GET" action="{{ url_for('view_authorizations') }}">
        <div class="form-group">
            <label for="userFilter">{{ _("Filter Users:") }}</label>
            <select id="userFilter" name="user" class="form-control">
                <option value="">{{ _("--Select User--")}}</option>
                {% for user in users %}
                <option value="{{ user.user_id }}" {% if request.args.get('user')|int == user.user_id %}selected{% endif %}>{{ user.name }} {{ user.surname }}</option>
                {% endfor %}
            </select>
        </div>
        <div class="form-group">
            <label for="machineFilter">{{ _("Filter Machines:") }}</label>
            <select id="machineFilter" name="machine" class="form-control">
                <option value="">{{ _("--Select Machine--") }}</option>
                {% for machine in machines %}
                <option value="{{ machine.machine_id }}" {% if request.args.get('machine')|int == machine.machine_id %}selected{% endif %}>{{ machine.machine_name }}</option>
                {% endfor %}
            </select>
        </div>
        <button type="submit" class="btn btn-info">{{ _("Apply Filters") }}</button>
    </form>
    <table class="table table-striped">
        <thead>
            <tr>
                <th>ID</th>
                <th>{{ _("User") }}</th>
                <th>{{ _("Machine") }}</th>
                <th>{{ _("Action") }}</th>
            </tr>
        </thead>
        <tbody>
            {% for authorization in authorizations %}
            <tr>
                <td>{{ authorization.authorization_id }}</td>
                <td>{{ authorization.user.name }} {{ authorization.user.surname }}</td>
                <td>{{ authorization.machine.machine_name }}</td>
                <td>
                    <a href="{{ url_for('edit_authorization', authorization_id=authorization.authorization_id) }}" class="btn btn-info">{{ _("Edit") }}</a>
                    <a href="{{ url_for('delete_authorization', authorization_id=authorization.authorization_id) }}" class="btn btn-danger">{{ _("Delete") }}</a>
                </td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
    <a href="{{ url_for('authorizations_export') }}" class="link-info"><i class="fas fa-file-excel"></i>{{ _("Export table") }}</a>
{% endblock %}
