{% load i18n l10n static %}
{% load itens_extras %}

<div class="mt-5">
  <h3>{{ titulo }}</h3>

  {% if lista %}
    <div class="row g-4">
      {% for leilao in lista %}
        {% include "auction/partials/_leilao_card.html" %}
      {% endfor %}
    </div>

    {% if page.has_other_pages %}
      <div class="mt-4">
        {% with current_page=page.number total_pages=page.paginator.num_pages has_previous=page.has_previous has_next=page.has_next previous_page_number=page.previous_page_number next_page_number=page.next_page_number %}
          {% if page.paginator.num_pages <= 7 %}
            {% with page_range=page.paginator.page_range show_first=False show_last=False show_first_ellipsis=False show_last_ellipsis=False query_params='' %}
              {% include 'includes/pagination_custom.html' %}
            {% endwith %}
          {% else %}
            {% if page.number <= 4 %}
              {% with page_range=page.paginator.page_range|slice:":5" show_first=False show_last=True show_first_ellipsis=False show_last_ellipsis=True query_params='' %}
                {% include 'includes/pagination_custom.html' %}
              {% endwith %}
            {% elif page.number >= page.paginator.num_pages|add:"-3" %}
              {% with page_range=page.paginator.page_range|slice:"-5:" show_first=True show_last=False show_first_ellipsis=True show_last_ellipsis=False query_params='' %}
                {% include 'includes/pagination_custom.html' %}
              {% endwith %}
            {% else %}
              {% with start=page.number|add:"-3" end=page.number|add:"2" %}
                {% with page_range=page.paginator.page_range|slice:start:end show_first=True show_last=True show_first_ellipsis=True show_last_ellipsis=True query_params='' %}
                  {% include 'includes/pagination_custom.html' %}
                {% endwith %}
              {% endwith %}
            {% endif %}
          {% endif %}
        {% endwith %}
      </div>
    {% endif %}
  {% else %}
    <div class="alert alert-secondary text-center" role="alert">
      {{ msg_vazio }}
    </div>
  {% endif %}
</div>
