{% load i18n spider_paging %}
{% list_parameters "search" as cur_search %}
{% list_parameters "info" as cur_info %}
{% get_searchpath as searchpath %}
<div class="">
  <form class="" style="white-space: nowrap;" method="POST" action="{{searchpath}}">
    {% csrf_token %}
    <select hidden="hidden" name="info" multiple="multiple">
      {% for elem in cur_info %}
        <option selected="selected" value="{{elem}}">{{elem}}</option>
      {% endfor %}
    </select>
    <select name="search" id="search_field_list_footer" multiple="multiple">
      {% for elem in cur_search %}
        <option selected="selected" value="{{elem}}">{{elem}}</option>
      {% endfor %}
    </select>
    <button class="w3-button w3-gray" aria-label="{% trans 'search' %}"><i class="fa fa-search" aria-hidden="true"></i></button>
    {% if cur_search or cur_info %}
      <button class="w3-button w3-gray" form="list_clear_form" aria-label="{% trans 'clear' %}">X</button>
    {% endif %}
  </form>
  <form hidden="hidden" id="list_clear_form" method="POST" action="{{searchpath}}">
    {% csrf_token %}
  </form>
  <div class="w3-text-grey w3-padding">
    <small>
      {% blocktrans %}
        Use ! to negate. Use !! to start a search tag with !. Press Enter to confirm tag. The button with the magnifying glass on the right starts the search.
      {% endblocktrans %}
    </small>
  </div>
</div>
<data hidden="hidden" property="spkc:pages.num_pages" datatype="xsd:PositiveInteger">{{page_obj.paginator.num_pages}}</data>
<data hidden="hidden" property="spkc:pages.size_page" datatype="xsd:PositiveInteger">{{page_obj.paginator.per_page}}</data>
{% if page_obj.paginator.num_pages > 1 %}
  <form class="w3-center" style="white-space: nowrap; margin-top:40px" method="POST">
    {% csrf_token %}
    <select hidden="hidden" name="search" multiple="multiple">
      {% for elem in cur_search %}
        <option selected="selected" value="{{elem}}">{{elem}}</option>
      {% endfor %}
    </select>

    <select hidden="hidden" name="info" multiple="multiple">
      {% for elem in cur_info %}
        <option selected="selected" value="{{elem}}">{{elem}}</option>
      {% endfor %}
    </select>
    {% if page_obj.has_previous %}
      <button type="submit" formaction="{{searchpath}}&page=1" >&laquo; first</button>
      <button type="submit" formaction="{{searchpath}}&page={{page_obj.previous_page_number}}" >{% trans "previous" %}</button>
    {% endif %}

    <span class="current">
      {% blocktrans trimmed with page=page_obj.number num_pages=page_obj.paginator.num_pages %}
        Page {{ page }} of {{ num_pages }}.
      {% endblocktrans %}
    </span>

    {% if page_obj.has_next %}
      <button type="submit" formaction="{{searchpath}}&page={{ page_obj.next_page_number }}">next</button>
      <button type="submit" formaction="{{searchpath}}&page={{ page_obj.paginator.num_pages }}">last &raquo;</button>
    {% endif %}
  </form>
{% endif %}

<script>
jQuery.noConflict();
var list_footer_scripts_initialized = false;

jQuery( document ).ready(function( $ ) {
  if (list_footer_scripts_initialized)
    return;
  list_footer_scripts_initialized = true;
  $("#search_field_list_footer").select2({
    tags: true,
    width: "80%",
    placeholder: "{% trans 'Search' %}",
  });
})

</script>
