{%- macro relations_list(relations) %}
    <ul class="list-unstyled">
        {%- for result in relations %}
            {%- with result_url=url_for('.item_view', item_id=result.id, _external=True), show_abstracts=False %}
                {%- include "kerko/_search-result.html.jinja2" %}
            {%- endwith %}
        {%- endfor %}
    </ul>
{%- endmacro %}

<div class="tab-pane fade {% if is_active %}show active{% endif %}" id="{{ key }}" role="tabpanel" aria-labelledby="tab-{{ key }}">
    <div class="d-none d-print-block font-weight-bold">{{ label }}</div>
    {%- if apply_relations_initial_limit %}
        {{ relations_list(item[field][:config.KERKO_RELATIONS_INITIAL_LIMIT]) }}
        {%- if item[field]|length > config.KERKO_RELATIONS_INITIAL_LIMIT %}
            <div class="collapse d-print-block" id="collapse-rel-{{ key }}">
                {{ relations_list(item[field][config.KERKO_RELATIONS_INITIAL_LIMIT:]) }}
            </div>
            <button class="btn btn-light d-print-none more-or-less" data-toggle="collapse" data-target="#collapse-rel-{{ key }}" aria-expanded="false" aria-controls="collapse-rel-{{ key }}">
                <span class="more">{{ _("View all") }}</span>
                <span class="less">{{ _("View fewer") }}</span>
            </button>
        {%- endif %}
    {%- else %}
        {{ relations_list(item[field]) }}
    {%- endif %}
</div>
