{%- from "kerko/_badges.html.jinja2" import badges %}

<li class="{% block search_list_item_classes %}search-item break-word my-3{% endblock %}">
    {%- if print_preview -%}
        {%- block search_item_print %}
            {{- badges(result, mode='result') -}}
            {%- block search_item_formatted_print %}
                {{- result.bib|safe -}}
            {%- endblock search_item_formatted_print %}
        {%- endblock search_item_print %}
    {%- else -%}
        {%- block search_item_display %}
            <div class="d-flex">
                <a class="{% block search_item_classes %}d-block mw-100 mr-auto{% endblock %}" href="{{ result_url }}" title="{{ _('View details') }}">
                    {{- badges(result, mode='result') -}}
                    {%- block search_item_formatted_display %}
                        {{- result.bib|safe -}}
                    {%- endblock search_item_formatted_display %}
                </a>
                {%- if result.coins %}
                    {{- result.coins|safe -}}
                {%- endif %}
            </div>
        {%- endblock search_item_display %}
    {%- endif -%}
    {%- if show_abstracts and result.data['abstractNote']|trim|length %}
        <p class="{% block search_abstract_classes %}search-abstract pre-line pl-3 my-2{% endblock %}">
            {%- if config.kerko.features.results_abstracts_max_length > 0 %}
                {{- result.data['abstractNote']|truncate(
                        config.kerko.features.results_abstracts_max_length,
                        leeway=config.kerko.features.results_abstracts_max_length_leeway
                    )|kerko_richtext_escape|urlize(target='_blank', rel="noopener noreferrer")|trim -}}
            {%- else %}
                {{- result.data['abstractNote']|kerko_richtext_escape|urlize(target='_blank', rel="noopener noreferrer")|trim -}}
            {%- endif %}
        </p>
    {%- endif %}
    {%- if not hide_result_links %}
        {%- block search_result_links %}
            {%- if result.attachments|length and config.kerko.features.results_attachment_links or result.url|kerko_url_hostname and config.kerko.features.results_url_links %}
                <div class="d-print-none btn-group {% block search_item_links_classes %}ml-2{% endblock %}">
                    {%- if config.kerko.features.results_attachment_links and result.attachments|length > 1 %}
                        {%- block search_result_link_multiple_attachments %}
                            <div class="dropdown">
                                <button class="{% block search_item_attachments_btn_classes %}btn btn-sm btn-link dropdown-toggle text-nowrap{% endblock %}" type="button" id="attachment-options-{{ result.id|escape }}" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                    <span class="fas fa-file mr-1" aria-hidden="true"></span>{{ _('Read documents') -}}
                                </button>
                                <span class="dropdown-menu dropdown-menu-right dropdown-width-300" aria-labelledby="attachment-options-{{ result.id|escape }}">
                                    {%- for attachment in result.attachments %}
                                        <a class="dropdown-item" href="{{ url_for('kerko.child_attachment_download', item_id=result.id, attachment_id=attachment['id'], attachment_filename=attachment['data']['filename']) }}"{% if config.kerko.features.download_attachment_new_window %} target="_blank" rel="noopener"{% endif %}>
                                            {{- attachment['data']['filename']|escape }}
                                        </a>
                                    {%- endfor %}
                                </span>
                            </div>
                        {%- endblock search_result_link_multiple_attachments %}
                    {%- elif config.kerko.features.results_attachment_links and result.attachments|length == 1 %}
                        {%- block search_result_link_single_attachment %}
                            <a class="{% block search_item_attachment_btn_classes %}btn btn-sm btn-link text-nowrap{% endblock %}" href="{{ url_for('kerko.child_attachment_download', item_id=result.id, attachment_id=result.attachments[0]['id'], attachment_filename=result.attachments[0]['data']['filename']) }}"{% if config.kerko.features.download_attachment_new_window %} target="_blank" rel="noopener"{% endif %} {{ title_aria_label(_('Read \'{}\'').format(result.attachments[0]['data']['filename']|escape)) }}>
                                <span class="fas fa-file mr-1" aria-hidden="true"></span>{{ _('Read document') -}}
                            </a>
                        {%- endblock search_result_link_single_attachment %}
                    {%- elif config.kerko.features.results_url_links and result.url|kerko_url_hostname %}
                        {%- block search_result_link_url %}
                            <a class="{% block search_item_link_btn_classes %}btn btn-sm btn-link text-nowrap{% endblock %}" href="{{ result.url|kerko_url_sanitize|escape }}" target="_blank" rel="noopener noreferrer">
                                <span class="fas fa-external-link-alt mr-1" aria-hidden="true"></span>{{ _('View on {}').format(result.url|kerko_url_hostname|escape) -}}
                            </a>
                        {%- endblock search_result_link_url %}
                    {%- endif %}
                </div>
            {%- endif %}
        {%- endblock search_result_links %}
    {%- endif %}
</li>
