{% extends "library/base.html" %}{% load i18n %}{% load molly_utils %}{% load molly_external_media %}

{% block content %}

{% if error_message %}
<div class="section">
    <div class="header">
        <h2>{% trans "There was an error with your search" %}</h2>
    </div>
    <div class="section-content">
        <p><strong>{{ error_message }}</strong></p>
    </div>
</div>
{% endif %}

{% if search_form %}{% include "library/search_form.html" %}{% endif %}

{% if page %}
<div class="section">
    <div class="header">
        <h2>{% trans "Result list" %} <small>({% trans "unsorted" %})</small></h2>
    </div>
    {% if removed %}
        <div class="note"><div class="bubble pad-10">
            {% blocktrans count removed|length as num_removed %}The following common word was not included in your query:{% plural %}The following common words were not included in your query:{% endblocktrans %}
                {% for w in removed %}{% if forloop.last %}{% if not forloop.first %}and {% endif %}<em>{{ w }}</em>{% else %}<em>{{ w }}</em>, {% endif %}{% endfor %}
        </div></div>
    {% endif %}

    <ul class="link-list" id="item-list">
        {% for item in page.object_list %}
            <li>
                {% if item.cover_image %}
                    {% with device|device_has_parent:"apple_iphone_ver4"|yesno:"120,60" as max_width %}
                        <img src="{% external_image item.cover_image max_width %}" alt="" style="border:0;" width="{{ max_width }}" />
                    {% endwith %}
                {% endif %}
                <a href="{% url library:item-detail item.control_number %}">
                    {{ item.title }}{% if item.author %}
                    <br/><small><strong>{% trans "Author" %}:</strong> {{ item.author }}</small>{% endif %}
                    <br/><small><strong>{% trans "Publisher" %}:</strong> {{ item.publisher }}</small>{% if item.edition %}
                    <br/><small><strong>{% trans "Edition" %}:</strong> {{ item.edition }}</small>{% endif %}
                    <br/><small><strong>{% trans "Libraries" %}:</strong> {{ item.holding_libraries }}</small>
                </a>
                
            </li>
            {% if item.pdf %}
            <li>
                <a href="{{ item.pdf }}">Download PDF {{ item.pdf }}</a>
            </li>
            {% endif %}
            {% if item.epub %}
            <li>
                <a href="{{ item.epub }}">Download epub {{ item.epub }}</a>
            </li>
            {% endif %}
        {% endfor %}
    </ul>

    <div class="note">
        {% if page.has_previous %}
            <a href="?title={{ search_form.cleaned_data.title|urlencode }}&author={{ search_form.cleaned_data.author|urlencode }}&isbn={{ search_form.cleaned_data.isbn|urlencode }}&page={{ page.previous_page_number }}" title="{% trans "Previous page" %}" class="prev">
                {% trans "Previous" %}</a>
        {% endif %}
        
        {% blocktrans with page.start_index as first_result and page.end_index as last_result and results.object_list|length as num_results and page.number as page_number and results.num_pages as number_of_pages %}Showing results {{ first_result }} to <span class="result-number">{{ last_result }}</span> of {{ num_results }}. Page <span class="current-page">{{ page_number }}</span> of {{ number_of_pages }}.{% endblocktrans %}
        
        {% if page.has_next %}
            <a href="?title={{ search_form.cleaned_data.title|urlencode }}&author={{ search_form.cleaned_data.author|urlencode }}&isbn={{ search_form.cleaned_data.isbn|urlencode }}&page={{ page.next_page_number }}" title="{% trans "Next page" %}" class="next">
                {% trans "Next" %}
            </a>
        {% endif %}
    </div>
</div>
{% endif %}

{% endblock %}
