{%- from "kerko/_attributes.html.jinja2" import title_aria_label %}

{%- macro sort_option_label(item, active) %}
    {{- _('Sort by {sort_option}').format(sort_option=item.label|escape) }}
    {%- if active %} ({{ _('Current sort') }}){% endif %}
{%- endmacro %}

{%- if sorter %}
    <div class="dropdown">
        <button class="{% block sorter_btn_classes %}btn btn-light dropdown-toggle{% endblock %}" type="button" id="sort-options" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" aria-label="{{ _('Sort by...') }}">
            <span aria-hidden="true">{{ _('Sort by: {sort_option}').format(sort_option=sorter.active) }}</span>{# -#}
        </button>
        <div class="dropdown-menu dropdown-menu-right" aria-labelledby="sort-options">
            {%- for item in sorter['items'] -%}
                <a class="dropdown-item{% if item.label == sorter.active %} active{% endif %}" href="{{ item.url }}" {% if item.label == sorter.active %}aria-current="true"{% endif %} {{ title_aria_label(sort_option_label(item, item.label == sorter.active)) }} rel="nofollow">
                    {{- item.label -}}
                </a>
            {%- endfor %}
        </div>
    </div>
{%- endif %}
