{% extends "_base.html" %}
{% load i18n %}
{% load static %}
{% block content %}
    <h1 class="heading">
        {% if view.kwargs.url_filter == 'valid' %}
            {% trans 'Valid links' %}
        {% elif view.kwargs.url_filter == 'invalid' %}
            {% trans 'Broken links' %}
        {% elif view.kwargs.url_filter == 'unchecked' %}
            {% trans 'Unchecked links' %}
        {% else %}
            {% trans 'Ignored links' %}
        {% endif %}
    </h1>
    <a href="{% if view.kwargs.url_filter == 'valid' %}#{% else %}{% url 'linkcheck' region_slug=request.region.slug url_filter='valid' %}{% if request.GET.size %}?size={{ request.GET.size }}{% endif %}{% endif %}"
       class="pr-2 {% if view.kwargs.url_filter == 'valid' %}text-black font-bold cursor-default{% else %}bg-transparent hover:underline text-blue-500 hover:text-blue-600 cursor-pointer{% endif %}">
        {% trans 'Valid' %}
        <span class="{% if view.kwargs.url_filter == 'valid' %}text-gray-500 font-normal{% endif %}">
            ({{ number_valid_urls }})
        </span>
    </a> |
    <a href="{% if view.kwargs.url_filter == 'invalid' %}#{% else %}{% url 'linkcheck' region_slug=request.region.slug url_filter='invalid' %}{% if request.GET.size %}?size={{ request.GET.size }}{% endif %}{% endif %}"
       class="pr-2 border-r-1 {% if view.kwargs.url_filter == 'invalid' %}text-black font-bold cursor-default{% else %}bg-transparent hover:underline text-blue-500 hover:text-blue-600 cursor-pointer{% endif %}">
        {% trans 'Invalid' %}
        <span class="{% if view.kwargs.url_filter == 'invalid' %}text-gray-500 font-normal{% endif %}">
            ({{ number_invalid_urls }})
        </span>
    </a> |
    <a href="{% if view.kwargs.url_filter == 'unchecked' %}#{% else %}{% url 'linkcheck' region_slug=request.region.slug url_filter='unchecked' %}{% if request.GET.size %}?size={{ request.GET.size }}{% endif %}{% endif %}"
       class="pr-2 border-r-1 {% if view.kwargs.url_filter == 'unchecked' %}text-black font-bold cursor-default{% else %}bg-transparent hover:underline text-blue-500 hover:text-blue-600 cursor-pointer{% endif %}">
        {% trans 'Unchecked' %}
        <span class="{% if view.kwargs.url_filter == 'unchecked' %}text-gray-500 font-normal{% endif %}">
            ({{ number_unchecked_urls }})
        </span>
    </a> |
    <a href="{% if view.kwargs.url_filter == 'ignored' %}#{% else %}{% url 'linkcheck' region_slug=request.region.slug url_filter='ignored' %}{% if request.GET.size %}?size={{ request.GET.size }}{% endif %}{% endif %}"
       class="{% if view.kwargs.url_filter == 'ignored' %}text-black font-bold cursor-default{% else %}bg-transparent hover:underline text-blue-500 hover:text-blue-600 cursor-pointer{% endif %}">
        {% trans 'Ignored' %}
        <span class="{% if view.kwargs.url_filter == 'ignored' %}text-gray-500 font-normal{% endif %}">
            ({{ number_ignored_urls }})
        </span>
    </a>
    {% if view.kwargs.url_id %}
        <form action="{{ request.path }}{{ pagination_params }}" method="post" id="edit-url-form">
            {% csrf_token %}
        </form>
    {% endif %}
    <form action="{{ request.path }}{{ pagination_params }}" method="post" id="bulk-action-form" class="table-listing">
        {% csrf_token %}
        <table class="w-full mt-4 rounded border border-solid border-gray-200 shadow bg-white">
            <thead>
                <tr class="border-b border-solid border-gray-200">
                    <th class="text-sm text-left uppercase py-3 pl-4 min">
                        <input type="checkbox" id="bulk-select-all"/>
                    </th>
                    <th class="text-sm text-left uppercase py-3 pr-2">{% trans 'URL' %}</th>
                    {% if request.user.expert_mode %}
                        <th class="text-sm text-left uppercase py-3 pr-2">{% trans 'Status' %}</th>
                    {% endif %}
                    <th class="text-sm text-left uppercase py-3 pr-2">{% trans 'Link text' %}</th>
                    <th class="text-sm text-left uppercase py-3 pr-2">{% trans 'Source' %}</th>
                    <th class="text-sm text-right uppercase py-3 pr-2">{% trans 'Usages' %}</th>
                    <th class="text-sm text-right uppercase py-3 pr-4">{% trans 'Options' %}</th>
                </tr>
            </thead>
            <tbody>
                {% for url in filtered_urls %}
                    {% include 'linkcheck/link_list_row.html' %}
                {% empty %}
                    <tr>
                        <td colspan="6" class="px-4 py-3">
                            {% if view.kwargs.url_filter == 'valid' %}
                                {% trans 'No valid links could be found.' %}
                            {% elif view.kwargs.url_filter == 'invalid' %}
                                {% trans 'No invalid links could be found.' %}
                            {% elif view.kwargs.url_filter == 'unchecked' %}
                                {% trans 'No unchecked links could be found.' %}
                            {% else %}
                                {% trans 'No ignored links could be found.' %}
                            {% endif %}
                        </td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
        {% if filtered_urls %}
            <div class="pt-2 px-2">
                <div class="inline">
                    <span class="text-gray-800 font-bold"
                    data-list-selection-count>0</span> <span class="text-gray-600">{% trans "Links selected" %}</span>
                </div>
            </div>
        {% endif %}
        <div class="flex flex-wrap relative w-1/2 mt-5 items-stretch gap-2">
            <select id="bulk-action" name="action" class="w-auto max-w-full">
                <option>
                    {% trans 'Select bulk action' %}
                </option>
                {% if view.kwargs.url_filter == 'ignored' %}
                    <option value="unignore"
                            data-bulk-action="{% url 'linkcheck' region_slug=request.region.slug url_filter=view.kwargs.url_filter %}{{ pagination_params }}">
                        {% trans 'Unignore' %}
                    </option>
                {% else %}
                    <option value="recheck"
                            data-bulk-action="{% url 'linkcheck' region_slug=request.region.slug url_filter=view.kwargs.url_filter %}{{ pagination_params }}">
                        {% trans 'Recheck' %}
                    </option>
                    <option value="ignore"
                            data-bulk-action="{% url 'linkcheck' region_slug=request.region.slug url_filter=view.kwargs.url_filter %}{{ pagination_params }}">
                        {% trans 'Ignore' %}
                    </option>
                {% endif %}
            </select>
            <button id="bulk-action-execute" class="btn" disabled>{% trans 'Execute' %}</button>
        </div>
    </form>
    {% url 'linkcheck' as url %}
    {% include 'pagination.html' with url=url chunk=page_obj %}
{% endblock content %}
