{% extends 'layout.html' %}
{% load i18n %}
{% load humanize %}

{% block title %}{% trans "Search" %}{% endblock %}

{% block content %}
<div class="block">
    <h1 class="title">
        {% blocktrans %}Search{% endblocktrans %}
    </h1>
</div>

<form class="block" action="{% url 'search' %}" method="GET">
    <div class="field has-addons">
        <div class="control">
            <input type="text" class="input" name="q" value="{{ query }}" aria-label="{% trans 'Search query' %}" id="tour-search-page-input">
        </div>
        <div class="control">
            <div class="select" aria-label="{% trans 'Search type' %}">
                <select name="type">
                    <option value="book" {% if type == "book" %}selected{% endif %}>{% trans "Books" %}</option>
                    {% if request.user.is_authenticated %}
                    <option value="user" {% if type == "user" %}selected{% endif %}>{% trans "Users" %}</option>
                    {% endif %}
                    <option value="list" {% if type == "list" %}selected{% endif %}>{% trans "Lists" %}</option>
                </select>
            </div>
        </div>
        <div class="control">
            <button type="submit" class="button is-primary">
                <span>Search</span>
                <span class="icon icon-search" aria-hidden="true"></span>
            </button>
        </div>
    </div>
</form>

{% if query %}
<nav class="tabs">
    <ul>
        <li{% if type == "book" %} class="is-active"{% endif %}>
            <a href="{% url 'search' %}?q={{ query }}&type=book">{% trans "Books" %}</a>
        </li>
        {% if request.user.is_authenticated %}
        <li{% if type == "user" %} class="is-active"{% endif %}>
            <a href="{% url 'search' %}?q={{ query }}&type=user">{% trans "Users" %}</a>
        </li>
        {% endif %}
        <li{% if type == "list" %} class="is-active"{% endif %}>
            <a href="{% url 'search' %}?q={{ query }}&type=list">{% trans "Lists" %}</a>
        </li>
    </ul>
</nav>

<section class="block" id="search-results-block">
    <p class="block">
        {% if not results %}
        <em>{% blocktrans %}No results found for "{{ query }}"{% endblocktrans %}</em>
        {% else %}
        <em>{% blocktrans trimmed count counter=results.paginator.count with result_count=results.paginator.count|intcomma %}
            {{ result_count }} result found
            {% plural %}
            {{ result_count }} results found
        {% endblocktrans %}</em>
        {% endif %}
    </p>
    {% block panel %}
    {% endblock %}

    <div class="block">
        {% include 'snippets/pagination.html' with page=results path=request.path %}
    </div>
    {% block search_footer %}{% endblock %}
</section>
{% endif %}

{% endblock %}

{% block scripts %}
{% if request.user.show_guided_tour %}
    {% include 'guided_tour/search.html' %}
{% endif %}
{% endblock %}
