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

{% block title %}{{ block.super }} - {% translate "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="mb-3">
            <label for="user-query" class="form-label">{% translate "Enter Search Query:" %}</label>
            <input type="text" name="q" id="user-query" class="form-control"
                   placeholder="{% translate "user name part" %}" value="{% if query %}{{ query }}{% endif %}">
        </div>
        <button type="submit" class="btn btn-primary">{% translate "Search" %}</button>
        <a class="btn btn-link" href="{% url 'impersonate-list' %}">{% translate "List all users" %}</a>
    </form>

    <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 }}">
                        {% blocktranslate %}Impersonate {{ user }}{% endblocktranslate %}</a>
                    </li>
                {% endfor %}
            </ul>
        {% endif %}
    </p>

    <p class="mt-3">
        {% 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 %}