{% extends 'layouts/base.html' %}

{% set page_title = 'Builds for ' + pkg.name %}

{% block body_header %}
<h2>Builds for {{pkg.name}}</h2>
{% endblock %}

{% block breadcrumbs %}
<nav class="pt-3" aria-label="breadcrumb">
    <ol class="breadcrumb">
        <li class="breadcrumb-item">
            <a href="{{ url_for('portal.repo_index', repo_name=pkg.repo.name) }}">Packages in {{pkg.repo.name}}</a>
        </li>
        <li class="breadcrumb-item">
            <a href="{{ url_for('packages.src_package_details',
                                repo_name=pkg.repo.name,
                                suite_name=pkg.suites[0].name,
                                name=pkg.name) }}">{{pkg.name}}</a>
        </li>
        <li class="breadcrumb-item">
            Builds
        </li>
    </ol>
</nav>
{% endblock %}

{% block body %}
<p><b>Latest</b>: {{pkg.version}}</p>
&nbsp;<br/>
<div class="columns">
    <div class="column is-half-desktop">

        {% if jobs_total == 0 %}
        <article class="message is-success" role="alert">
            <div class="message-body">
                <span class="fa fa-check" aria-hidden="true"></span> There are no build jobs for this package!
            </div>
        </article>


        {% else %}
          {% for arch_name, jobs in jobs_arch.items() %}
          {% if jobs %}
                <h3 class=""><i class="fas fa-microchip"></i>&nbsp;{{arch_name}}</h3>
                &nbsp;<br/>
                {% for j in jobs %}
                  {% set item_style = '' %}
                  {% if j.status == JobStatus.DONE %}
                    {% if j.result == JobResult.SUCCESS_PENDING or j.result == JobResult.SUCCESS %}
                      {% set item_style = 'is-success' %}
                    {% elif j.result == JobResult.FAILURE_DEPENDENCY %}
                      {% set item_style = 'is-dark' %}
                    {% else %}
                      {% set item_style = 'is-danger' %}
                    {% endif %}
                  {% else %}
                    {% if j.status == JobStatus.SCHEDULED %}
                      {% set item_style = 'is-info' %}
                    {% elif j.status == JobStatus.RUNNING %}
                      {% set item_style = 'is-primary' %}
                    {% elif j.status == JobStatus.DEPWAIT %}
                      {% set item_style = 'is-warning' %}
                    {% endif %}
                {% endif %}
                <article class="message {{item_style}}" role="alert">
                    <div class="message-body">
                        <a href="{{ url_for('packages.build_details', uuid=j.uuid) }}">
                            <h4>{{j.version}}</h4>
                            <p>
                                <i class="fas fa-star-of-life"></i> {{humanized_timediff(j.time_created)}}
                            </p>
                        </a>
                    </div>
                </article>
            {% endfor %}

          {% endif %}
          {% endfor %}
        {% endif %}
    </div>
</div>

<br/>
{% if page_count > 1 %}
<nav class="pagination is-centered" role="navigation" aria-label="pagination">

    <a class="pagination-previous" href="{{ url_for('packages.builds_list', name=pkg.name, page=current_page-1) if current_page > 1 else '#'}}" aria-label="Previous">
        Previous
    </a>
    <a class="pagination-next" href="{{ url_for('packages.builds_list', name=pkg.name, page=current_page+1) if current_page < page_count else '#'}}" aria-label="Next">
        Next
    </a>

    {% for i in range(1, page_count + 1) %}
    <ul class="pagination-list">
        <li>
            <a class="pagination-link {{'is-current' if i == current_page }}" href="{{ url_for('packages.builds_list', name=pkg.name, page=i) }}">{{i}}</a>
        </li>
    </ul>
    {% endfor %}

</nav>
{% endif %}

{% endblock %}
