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

{% block content %}
    <h2>{% trans "Search" %}</h2>
    <form method="get" action="{{ request.path }}">
        <div class="well clearfix">
            {{ form.as_p }}
            <p class="pull-right">
                <input type="submit" value="Search"
                       class="btn btn-primary">
            </p>
        </div>
    </form>

    {% if query %}
        <h3>{% trans "Results" %}</h3>

        {% for result in page.object_list %}
            <p>
                <a href="{{ result.object.get_url_path }}">
                    {{ result.object.title }}
                </a>
            </p>
        {% empty %}
            <p>{% trans "No results found." %}</p>
        {% endfor %}

        {% if page.has_previous or page.has_next %}
            <nav>
                <ul class="pager">
                    <li class="previous">
                        {% if page.has_previous %}
                            <a href="{% modify_query page=page.previous_page_number %}">
                        {% endif %}
                        <span aria-hidden="true">&laquo;</span>
                        {% if page.has_previous %}</a>{% endif %}
                    </li>
                    {% for num in page.paginator.page_range %}
                        <li{% if num = page.number %}
                            class="selected"{% endif %}>
                            <a href="{% modify_query page=num %}">
                                {{ num }}</a>
                        </li>
                    {% endfor %}
                    <li class="next">
                        {% if page.has_next %}
                            <a href="{% modify_query page=page.next_page_number %}">
                        {% endif %}
                        <span aria-hidden="true">&raquo;</span>
                        {% if page.has_next %}</a>{% endif %}
                    </li>
                </ul>
            </nav>
        {% endif %}
    {% endif %}
{% endblock %}
