{% extends "_base.html" %}
{% load i18n %}
{% load static %}
{% block content %}
    <div class="flex flex-wrap justify-between gap-4">
        <h1 class="heading">
            {% if view.kwargs.url_filter == 'valid' %}
                {% translate "Valid links" %}
            {% elif view.kwargs.url_filter == 'invalid' %}
                {% translate "Broken links" %}
            {% elif view.kwargs.url_filter == 'unchecked' %}
                {% translate "Unchecked links" %}
            {% elif view.kwargs.url_filter == 'ignored' %}
                {% translate "Ignored links" %}
            {% elif LINKCHECK_EMAIL_ENABLED and view.kwargs.url_filter == 'email' %}
                {% translate "Email links" %}
            {% elif LINKCHECK_PHONE_ENABLED and view.kwargs.url_filter == 'phone' %}
                {% translate "Phone links" %}
            {% else %}
                {% translate "All links" %}
            {% endif %}
        </h1>
        {% if request.user.expert_mode %}
            <a href="{% url 'search_and_replace_link' region_slug=request.region.slug %}"
               class="font-bold text-sm text-gray-800 flex items-center gap-1 mb-2 hover:underline">
                <span><i icon-name="replace" class="align-top h-5"></i> {% translate "Search & replace" %}</span>
            </a>
        {% endif %}
    </div>
    <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 %}">
        {% translate "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="px-2 border-l-2 border-gray-500 {% 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 %}">
        {% translate "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="px-2 border-l-2 border-gray-500 {% 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 %}">
        {% translate "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="px-2 border-l-2 border-gray-500 {% 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 %}">
        {% translate "Ignored" %}
        <span class="{% if view.kwargs.url_filter == 'ignored' %}text-gray-500 font-normal{% endif %}">
            ({{ number_ignored_urls }})
        </span>
    </a>
    {% if request.user.expert_mode %}
        {% if LINKCHECK_EMAIL_ENABLED %}
            <a href="{% if view.kwargs.url_filter == 'email' %}#{% else %}{% url 'linkcheck' region_slug=request.region.slug url_filter='email' %}{% if request.GET.size %}?size={{ request.GET.size }}{% endif %}{% endif %}"
               class="px-2 border-l-2 border-gray-500 {% if view.kwargs.url_filter == 'email' %}text-black font-bold cursor-default{% else %}bg-transparent hover:underline text-blue-500 hover:text-blue-600 cursor-pointer{% endif %}">
                {% translate "Email links" %}
                <span class="{% if view.kwargs.url_filter == 'email' %}text-gray-500 font-normal{% endif %}">
                    ({{ number_email_urls }})
                </span>
            </a>
        {% endif %}
        {% if LINKCHECK_PHONE_ENABLED %}
            <a href="{% if view.kwargs.url_filter == 'phone' %}#{% else %}{% url 'linkcheck' region_slug=request.region.slug url_filter='phone' %}{% if request.GET.size %}?size={{ request.GET.size }}{% endif %}{% endif %}"
               class="px-2 border-l-2 border-gray-500 {% if view.kwargs.url_filter == 'phone' %}text-black font-bold cursor-default{% else %}bg-transparent hover:underline text-blue-500 hover:text-blue-600 cursor-pointer{% endif %}">
                {% translate "Phone links" %}
                <span class="{% if view.kwargs.url_filter == 'phone' %}text-gray-500 font-normal{% endif %}">
                    ({{ number_phone_urls }})
                </span>
            </a>
        {% endif %}
    {% endif %}
    {% 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">
                        {% translate "URL" %}
                    </th>
                    {# djlint:off H023 #}
                    <th class="text-sm text-left uppercase py-3 pr-2 min"
                        title="{% translate "SSL is the standard technology for securing Internet connections and protecting sensitive data transferred between two systems." %}&#013;&#013;{% translate "When a website is secured by an SSL certificate, its URL starts with 'https', insecure links with 'http' should no longer be used." %}">
                        {% translate "SSL" %}
                    </th>
                    {# djlint:on #}
                    {% if request.user.expert_mode %}
                        <th class="text-sm text-left uppercase py-3 pr-2 min"
                            title="{% translate "An anchor denotes a link to a fragement within an HTML document" %}">
                            {% translate "Anchor" %}
                        </th>
                    {% endif %}
                    <th class="text-sm text-left uppercase py-3 pr-2 min"
                        title="{% translate "HTTP response status codes indicate whether a specific HTTP request has been successfully completed." %}">
                        {% translate "Code" %}
                    </th>
                    <th class="text-sm text-left uppercase py-3 pr-2">
                        {% translate "Status" %}
                    </th>
                    <th class="text-sm text-left uppercase py-3 pr-2"
                        title="{% translate "The link text of the first usage" %}">
                        {% translate "Link text" %}
                    </th>
                    <th class="text-sm text-left uppercase py-3 pr-2"
                        title="{% translate "The source translation of the first usage" %}">
                        {% translate "Source" %}
                    </th>
                    <th class="text-sm text-right uppercase py-3 pr-2 lg:max-w-[50px] xl:max-w-[100px] 2xl:max-w-full truncate min"
                        title="{% translate "The number of times this URL is used in the content" %}">
                        {% translate "Usages" %}
                    </th>
                    <th class="text-sm text-right uppercase py-3 pr-4 min">
                        {% translate "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' %}
                                {% translate "No valid links could be found." %}
                            {% elif view.kwargs.url_filter == 'invalid' %}
                                {% translate "No invalid links could be found." %}
                            {% elif view.kwargs.url_filter == 'unchecked' %}
                                {% translate "No unchecked links could be found." %}
                            {% elif LINKCHECK_EMAIL_ENABLED and view.kwargs.url_filter == 'email' %}
                                {% translate "No email links could be found." %}
                            {% elif LINKCHECK_PHONE_ENABLED and view.kwargs.url_filter == 'phone' %}
                                {% translate "No phone links could be found." %}
                            {% else %}
                                {% translate "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">{% translate "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>
                    {% translate "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 }}">
                        {% translate "Unignore" %}
                    </option>
                {% else %}
                    <option value="recheck"
                            data-bulk-action="{% url 'linkcheck' region_slug=request.region.slug url_filter=view.kwargs.url_filter %}{{ pagination_params }}">
                        {% translate "Recheck" %}
                    </option>
                    <option value="ignore"
                            data-bulk-action="{% url 'linkcheck' region_slug=request.region.slug url_filter=view.kwargs.url_filter %}{{ pagination_params }}">
                        {% translate "Ignore" %}
                    </option>
                {% endif %}
            </select>
            <button id="bulk-action-execute" class="btn" disabled>
                {% translate "Execute" %}
            </button>
        </div>
    </form>
    {% url 'linkcheck' as url %}
    {% include "pagination.html" with url=url chunk=page_obj %}
{% endblock content %}
