{% set apply_relations_initial_limit = True %}
{% extends config.kerko.templates.item %}
{% from "kerko/_breadcrumb.html.jinja2" import breadcrumb %}

{%- block metas %}
    {{- super() }}
    {%- include "kerko/_search-metas.html.jinja2" %}
{%- endblock metas %}

{%- block breadcrumb %}
    {%- if is_searching and back_url %}
        {{ breadcrumb([{'url': back_url, 'text': _("Your search")}, title]) }}
    {%- else %}
        {{ super() }}
    {%- endif %}
{%- endblock breadcrumb %}

{%- block content_header %}
    <div class="mt-2 row">
        <h1 class="{% block search_heading_classes %}h4 col-auto mr-auto pr-1 d-inline d-print-none{% endblock %}">
            {{- search_title -}}
        </h1>
        {%- if back_url %}
            <div class="{% block back_link_wrapper_classes %}col-auto ml-auto mb-2 pl-1 text-right d-print-none{% endblock %}">
                <a class="{% block back_btn_classes %}btn btn-primary{% endblock %}" href="{{ back_url }}">
                    <span class="fas fa-arrow-left" aria-hidden="true"></span> {{ _("Return to list of results") }}
                </a>
            </div>
        {%- endif %}
    </div>
{%- endblock content_header %}

{%- block content_inner %}
    {%- block search_criteria %}
        {%- if is_searching %}
            <div class="{% block search_criteria_wrapper_classes %}card breadbox mb-4 d-print-none{% endblock %}">
                <div class="card-body">
                    {%- include "kerko/_breadbox.html.jinja2" %}
                </div>
            </div>
        {%- endif %}
    {%- endblock search_criteria %}
    {%- block search_results %}
        {%- include "kerko/_pager.html.jinja2" %}
        <h2 class="{% block item_heading_classes %}my-3 clearfix{% endblock %}">
            {{- badges(item, mode='item') -}}
            {{- title|kerko_richtext_escape -}}
        </h2>
    {%- endblock search_results %}
    {{- super() }}
    {%- include "kerko/_pager.html.jinja2" %}
{%- endblock content_inner %}

{%- block body_scripts %}
    {{ super() }}
    {%- if preferred_url %}
        <script>
            history.replaceState({}, "", "{{ preferred_url }}");
        </script>
    {%- endif %}
{%- endblock body_scripts %}
