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

{% block title %}{{ block.super }} - {% trans "Django Impersonate - Search Users" %}{% endblock title %}
{% block page_title %}Search Users {% if query %}- Page {{ page_number }}{% endif %}{% endblock page_title %}

{% block content %}
    <form action="{% url 'impersonate-search' %}" method="GET">
        {{ redirect_field }}
        <div class="form-group">
            <label for="user-query">{% trans "Enter Search Query:" %}</label>
            <input type="text" name="q" id="user-query" class="form-control"
                   value="{% if query %}{{ query }}{% endif %}">
        </div>
        <button type="submit" class="btn btn-primary">{% trans "Search" %}</button>
    </form>

    <p>
        <a href="{% url 'impersonate-list' %}">{% trans "List all users" %}</a>
    </p>

    <p>
        {% if query and page.object_list %}
            <ul class="list-group">
                {% for user in page.object_list %}
                    <li class="list-group-item"><a
                            href="{% url 'impersonate-start' user.pk %}{{ redirect }}">{{ user }}</a> - Impersonate
                    </li>
                {% endfor %}
            </ul>
        {% endif %}
    </p>

    <p>
        {% if query and page.has_previous %}
            <a href="{% url 'impersonate-search' %}?page={{ page.previous_page_number }}&q={{ query|urlencode }}">Previous
                Page</a> &nbsp;
        {% endif %}

        {% if query and page.has_next %}
            <a href="{% url 'impersonate-search' %}?page={{ page.next_page_number }}&q={{ query|urlencode }}">Next
                Page</a>
        {% endif %}
    </p>
{% endblock %}