{% extends 'dashboard/layout.html' %}
{% load dashboard_tags %}
{% load i18n %}

{% block title %}
{% trans "Approvers" %} | {{ block.super }}
{% endblock %}

{% block breadcrumbs %}
<ul class="breadcrumb">
    <li>
    <a href="{% url dashboard:index %}">{% trans "Dashboard" %}</a>
        <span class="divider">/</span>
    </li>
    <li class="active"><a href=".">{% trans "Approvers" %}</a></li>
</ul>
{% endblock %}

{% block header %}
<div class="page-header">
    <h1>{% trans "Order reviewers" %}</h1>
</div>
{% endblock header %}

{% block dashboard_content %}
<div class="well well-info">
    <h3 class="app-ico ico_magnify icon">{% trans "Add an reviewer" %}</h3>
    <form action="." method="get" class="form-inline">
        {% include "partials/form_fields_inline.html" with form=form %}
        <input type="submit" value="{% trans "Search" %}" class="btn btn-primary"/>
        <a href="{% url dashboard:users-index %}" class="btn">{% trans "Reset" %}</a>
    </form>
</div>
{% if form.is_bound %}
    <div class="sub-header">
        <h2>Search results</h2>
    </div>
    {% if object_list %}
    <table class="table table-striped table-bordered">
        <tr>
            <th>{% trans "Email" %}</th>
            <th>{% trans "First name" %}</th>
            <th>{% trans "Last name" %}</th>
            <th>{% trans "Active" %}</th>
            <th>{% trans "Staff status" %}</th>
            <th>{% trans "Is a reviewer?" %}</th>
            <th></th>
        </tr>
        {% for profile in object_list %}
        <tr>
            <td>{{ profile.user.email }}</td>
            <td>{{ profile.user.first_name }}</td>
            <td>{{ profile.user.last_name }}</td>
            <td>{{ profile.user.is_active }}</td>
            <td>{{ profile.user.is_staff }}</td>
            <td>{{ profile.is_order_approver }}</td>
            <td>
                <form action="{% if profile.is_order_approver %}{% url dashboard:approver-remove profile.pk %}{% else %}{% url dashboard:approver-add profile.pk %}{% endif %}" method="post" class="form-inline">
                    {% csrf_token %}
                    {% if profile.is_order_approver %}
                        <input type="submit" value="{% trans "Remove reviewer" %}" class="btn btn-primary"/>
                    {% else %}
                        <input type="submit" value="{% trans "Add reviewer" %}" class="btn btn-primary"/>
                    {% endif %}
                </form>
            </td>
        </tr>
        {% endfor %}
    </table>
    {% else %}
    <p>{% trans "No users found." %}</p>
    {% endif %}
{% endif %}


<div class="page-header">
    <h1>{% trans "Current order reviewers" %}</h1>
</div>
{% if approvers %}
<table class="table table-striped table-bordered">
    <tr>
        <th>{% trans "Email" %}</th>
        <th>{% trans "First name" %}</th>
        <th>{% trans "Last name" %}</th>
        <th>{% trans "Active" %}</th>
        <th>{% trans "Staff status" %}</th>
        <th>{% trans "Is a reviewer?" %}</th>
        <th></th>
    </tr>
    {% for profile in approvers %}
    <tr>
        <td>{{ profile.user.email }}</td>
        <td>{{ profile.user.first_name }}</td>
        <td>{{ profile.user.last_name }}</td>
        <td>{{ profile.user.is_active }}</td>
        <td>{{ profile.user.is_staff }}</td>
        <td>{{ profile.is_order_approver }}</td>
        <td>
            <form action="{% if profile.is_order_approver %}{% url dashboard:approver-remove profile.pk %}{% else %}{% url dashboard:approver-add profile.pk %}{% endif %}" method="post" class="form-inline">
                {% csrf_token %}
                {% if profile.is_order_approver %}
                    <input type="submit" value="{% trans "Remove reviewer" %}" class="btn btn-primary"/>
                {% else %}
                    <input type="submit" value="{% trans "Add reviewer" %}" class="btn btn-primary"/>
                {% endif %}
            </form>
        </td>
    </tr>
    {% endfor %}
</table>

{% if page_obj %}
    {% include "catalogue/partials/pagination.html" %}
{% endif %}

{% else %}

<p>{% trans "There are currently no reviewers." %}</p>

{% endif %}

{% endblock dashboard_content %}
