{% extends "base.html" %}
{% load humanize %}
{% load widget_tweaks %}

{% block title %}
VulnerableCode Package Search
{% endblock %}

{% block content %}

{% include "navbar.html" %}

<section class="section pt-0">
    {% include "package_search_box.html" %}
</section>

{% if search %}
    <div class="is-max-desktop mb-3">
        <section class="mx-5">
            <div class="is-flex" style="justify-content: space-between;">
                <div>
                    {{ page_obj.paginator.count|intcomma }} results
                </div>
                {% if is_paginated %}
                    {% include 'includes/pagination.html' with page_obj=page_obj %}
                {% endif %}
            </div>
        </section>
    </div>
   
    <section class="section pt-0">
        <div class="content">
            <table class="table is-bordered is-striped is-narrow is-hoverable is-fullwidth">
                <thead>
                    <tr>
                        <th>
                            <span
                                class="has-tooltip-multiline has-tooltip-black has-tooltip-arrow has-tooltip-text-left"
                                data-tooltip="The package url or purl is a URL string used to identify and locate a software package.">
                                Package URL
                            </span>
                        </th>
                        <th style="width: 225px;">
                            <span
                                class="has-tooltip-multiline has-tooltip-black has-tooltip-arrow has-tooltip-text-left"
                                data-tooltip="This is the number of vulnerabilities that affect the package.">
                                Affected by vulnerabilities
                            </span>
                        </th>
                        <th style="width: 225px;">
                            <span
                                class="has-tooltip-multiline has-tooltip-black has-tooltip-arrow has-tooltip-text-left"
                                data-tooltip="This is the number of vulnerabilities fixed by the package.">
                                Fixing vulnerabilities
                            </span>
                        </th>
                    </tr>
                </thead>
                <tbody>
                    {% for package in page_obj %}
                        <tr>
                            <td style="word-break: break-all;">
                                <a
                                    href="{{ package.get_absolute_url }}?search={{ search }}"
                                    target="_self">{{ package.purl }}</a>
                            </td>
                            <td>{{ package.vulnerability_count }}</td>
                            <td>{{ package.patched_vulnerability_count }}</td>
                        </tr>
                    {% empty %}
                        <tr>
                            <td colspan="3" style="word-break: break-all;">
                            No Package found.
                            </td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>

    {% if is_paginated %}
        {% include 'includes/pagination.html' with page_obj=page_obj %}
    {% endif %}

    </section>
{% endif %}
{% endblock %}
