{% comment %}
Переиспользуемый компонент для заголовков таблиц с сортировкой
Использование:
    {% include 'mainapp/components/_table_header.html' with label="Имя" field="name" sort=sort %}
    {% include 'mainapp/components/_table_header.html' with label="Частота" field="frequency" sort=sort sortable=False %}
{% endcomment %}

<th scope="col">
    {% if sortable != False %}
    <a href="?{% for key, value in request.GET.items %}{% if key != 'page' and key != 'sort' %}{{ key }}={{ value }}&{% endif %}{% endfor %}sort={% if sort == field %}-{{ field }}{% elif sort == '-'|add:field %}{{ field }}{% else %}{{ field }}{% endif %}" 
       class="text-white text-decoration-none d-inline-flex align-items-center">
        {{ label }}
        {% if sort == field %}
            <i class="bi bi-sort-up ms-1"></i>
            <a href="?{% for key, value in request.GET.items %}{% if key != 'page' and key != 'sort' %}{{ key }}={{ value }}&{% endif %}{% endfor %}" 
               class="text-white ms-1" title="Сбросить сортировку">
                <i class="bi bi-x-lg"></i>
            </a>
        {% elif sort == '-'|add:field %}
            <i class="bi bi-sort-down ms-1"></i>
            <a href="?{% for key, value in request.GET.items %}{% if key != 'page' and key != 'sort' %}{{ key }}={{ value }}&{% endif %}{% endfor %}" 
               class="text-white ms-1" title="Сбросить сортировку">
                <i class="bi bi-x-lg"></i>
            </a>
        {% else %}
            <i class="bi bi-arrow-down-up ms-1"></i>
        {% endif %}
    </a>
    {% else %}
    {{ label }}
    {% endif %}
</th>
