{% load static %}
<h3>By {{ title }}</h3>
<ul>
{% for choice in choices %}
    <li{% if choice.selected %} class="selected"{% endif %}>
        <span style='float: left;'>
            <a href="{{ choice.query_string|iriencode }}" title="{{ choice.display }}">
                {{ choice.display }}
            </a>
        </span>

        <span style='float: right;'>
            {% if forloop.first %}
                <a href='/dynfilters/{{ spec.model_name }}/add/?next={{ spec.referer|urlencode }}' title="Create new filter">
                    <img src="{% static 'admin/img/icon-addlink.svg' %}">
                </a>

            {% else %}
                <a href='/admin/dynfilters/dynamicfilterexpr/{{ choice.lookup }}/change/?next={{ spec.referer|urlencode }}' title="Edit filter" style="display:inline;">
                    <img src="{% static 'admin/img/icon-changelink.svg' %}">
                </a>

                <a href="mailto:?subject={{ spec.email_subject|iriencode }}&body={{ spec.email_text|iriencode }}{{ choice.email_body|urlencode }}" title="Share filter" style="display:inline;">
                    <img src="{% static 'img/dynfilters/icon-share.svg' %}">
                </a>

                <a href="#" onclick="javascript:confirmDelete('/dynfilters/{{ choice.lookup }}/delete/');" title="Delete filter" style="display:inline;">
                    <img src="{% static 'admin/img/icon-deletelink.svg' %}">
                </a>

            {% endif %}
        </span>

        <div style='clear:both;'></div>
    </li>
{% endfor %}
</ul>

<script>
function confirmDelete(href) {
    const deleteLocation = confirm('Do you really want to delete this filter?');
    if (deleteLocation) {
        window.location = href;
    }
}
</script>
