{% load debusine %}
<ul>
    <li>
        Result:
        {% include "web/_work_request-result.html" %}
    </li>
    <li>Fail on: {{ fail_on_severity }}</li>
    {% if lintian_txt_path %}
        <li>
            <a href="{{ lintian_txt_path }}">Lintian output</a>
        </li>
    {% endif %}
</ul>
<h2>Summary of tags</h2>
<div id="lintian-severity-filter" class="mb-3">
    <p class="text-muted mb-2">Click to show/hide tags for a severity:</p>
    <div class="row">
        <div class="col-md-6 d-flex flex-column align-items-start gap-2">
            {% include "web/_lintian_severity_filter.html" with severity="error" status=tags_filter_status.error only %}
            {% include "web/_lintian_severity_filter.html" with severity="warning" status=tags_filter_status.warning only %}
            {% include "web/_lintian_severity_filter.html" with severity="info" status=tags_filter_status.info only %}
            {% include "web/_lintian_severity_filter.html" with severity="pedantic" status=tags_filter_status.pedantic only %}
        </div>
        <div class="col-md-6 d-flex flex-column align-items-start gap-2">
            {% include "web/_lintian_severity_filter.html" with severity="experimental" status=tags_filter_status.experimental only %}
            {% include "web/_lintian_severity_filter.html" with severity="overridden" status=tags_filter_status.overridden only %}
            {% include "web/_lintian_severity_filter.html" with severity="classification" status=tags_filter_status.classification only %}
        </div>
    </div>
</div>
{% for file, file_tags in tags.items %}
    <div class="lintian-file-tags">
        <h3>{{ file }}</h3>
        {% for tag_name, tag_content in file_tags.items %}
            <div class="lintian-tag"
                 data-lintian-tag-severity="{{ tag_content.severity }}">
                <h4>
                    {% include "web/_tag_severity.html" with severity=tag_content.severity only %}
                    {{ tag_name }}
                </h4>
                {% if tag_content.explanation %}
                    {% include "web/_tag_explanation.html" with tag_content=tag_content only %}
                {% endif %}
                <ul>
                    {% for tag in tag_content.occurrences %}
                        <li>{% include "web/_lintian_tag.html" with tag=tag only %}</li>
                    {% endfor %}
                </ul>
            </div>
        {% endfor %}
    </div>
{% endfor %}
<script>
    (function () {
        const toggles = document.querySelectorAll(
            "[data-lintian-severity-toggle]"
        );

        function updateLintianSeverityFilter() {
            const enabledSeverities = new Set(
                Array.from(toggles)
                    .filter((toggle) => toggle.checked)
                    .map((toggle) => toggle.dataset.lintianSeverityToggle)
            );

            document.querySelectorAll(".lintian-tag").forEach((tag) => {
                tag.hidden = !enabledSeverities.has(
                    tag.dataset.lintianTagSeverity
                );
            });

            document.querySelectorAll(".lintian-file-tags").forEach((file) => {
                file.hidden = !file.querySelector(".lintian-tag:not([hidden])");
            });
        }

        toggles.forEach((toggle) => {
            toggle.addEventListener("change", updateLintianSeverityFilter);
        });
        updateLintianSeverityFilter();
    })();
</script>
