{% if vulns %}
{% set crit = [] %}{% set high = [] %}{% set med = [] %}{% set low = [] %}
{% for v in vulns %}
    {% if v.branch_status != "fixed" and not v.report_stale %}
    {% if v.severity == "critical" %}{% if crit.append(1) %}{% endif %}
    {% elif v.severity == "high" %}{% if high.append(1) %}{% endif %}
    {% elif v.severity == "medium" %}{% if med.append(1) %}{% endif %}
    {% else %}{% if low.append(1) %}{% endif %}
    {% endif %}
    {% endif %}
{% endfor %}

<div class="stats-bar">
    <div class="stat-chip">
        <span class="stat-chip-value">{{ vulns | length }}</span>
        <span class="stat-chip-label">shown</span>
    </div>
    {% if crit %}
    <div class="stat-chip stat-chip-danger">
        <span class="stat-chip-value">{{ crit | length }}</span>
        <span class="stat-chip-label">critical</span>
    </div>
    {% endif %}
    {% if high %}
    <div class="stat-chip stat-chip-warning">
        <span class="stat-chip-value">{{ high | length }}</span>
        <span class="stat-chip-label">high</span>
    </div>
    {% endif %}
    {% if med %}
    <div class="stat-chip stat-chip-info">
        <span class="stat-chip-value">{{ med | length }}</span>
        <span class="stat-chip-label">medium</span>
    </div>
    {% endif %}
    {% if low %}
    <div class="stat-chip">
        <span class="stat-chip-value">{{ low | length }}</span>
        <span class="stat-chip-label">low</span>
    </div>
    {% endif %}
</div>

<table class="sortable vulns-table">
    <thead>
        <tr>
            <th>Repo</th>
            <th>Severity</th>
            <th>Name</th>
            <th>Source</th>
            <th>Location</th>
            <th>State</th>
            <th>Mitigation</th>
        </tr>
    </thead>
    <tbody>
        {% for v in vulns %}
        <tr{% if v.branch_status == "fixed" or v.report_stale %} class="vuln-fixed"{% endif %}>
            <td><a href="/repo/{{ v.repo_name }}?from=vulns"><code title="{{ v.repo_name }}">{{ v.repo_name }}</code></a></td>
            <td data-sort="{% if v.severity == 'critical' %}0{% elif v.severity == 'high' %}1{% elif v.severity == 'medium' %}2{% else %}3{% endif %}">
                <span class="badge-{{ v.severity }}">{{ v.severity }}</span>
            </td>
            <td>
                <a href="{{ v.web_url }}" target="_blank">{{ v.name }}</a>
                {% if v.branch_status == "fixed" %}<br><span class="badge-fixed">fixed in branch</span>{% endif %}
                {% if v.branch_status == "outdated_branch" %}<br><span class="badge-outdated">run branch pipeline</span>{% endif %}
                {% if v.branch_status == "outdated_default" %}<br><span class="badge-outdated">run default pipeline</span>{% endif %}
                {% if v.branch_status == "introduced" %}<br><span class="badge-introduced">introduced in branch</span>{% endif %}
                {% if v.report_stale %}<br><span class="badge-fixed">stale report</span>{% endif %}
            </td>
            <td class="nowrap"><code>{{ v.source }}</code></td>
            <td class="break-url">{% if v.location %}<code title="{{ v.location }}">{{ v.location }}</code>{% endif %}</td>
            <td><span class="badge-{{ v.state | lower }}">{{ v.state }}</span></td>
            <td class="nowrap">{% if v.solution %}<code title="{{ v.solution }}">{{ v.solution }}</code>{% elif v.mitigation_state %}<span class="badge-dismissed">{{ v.mitigation_state | replace("_", " ") }}</span>{% if v.mitigation_details %} <small>{{ v.mitigation_details }}</small>{% endif %}{% else %}<span class="text-center-muted">none</span>{% endif %}</td>
        </tr>
        {% endfor %}
    </tbody>
</table>
{% else %}
<p class="text-center-muted">No vulnerabilities{% if filter and filter != "all" %} matching filter{% endif %}.</p>
{% endif %}
