{% extends "layout.html" %}
{% from "_helpers.html" import render_field, render_pagination, build_href %}

{% block title %}Package search{% endblock %}
{% block header %}Package search{% endblock %}

{% block breadcrumbs %}
<ol class="breadcrumb">
  <li>
    <a href="{{ url_for('coprs_ns.coprs_show') }}">Home</a>
  </li>
  <li class="active">
    Package search
  </li>
</ol>
{% endblock %}

{% block body %}
<h1>Search built packages</h1>
<p>Search built packages by NEVRA fields across all build chroot results.</p>

<form class="form-horizontal" method="get" action="{{ url_for('coprs_ns.build_chroot_results_search') }}">
  {{ form.csrf_token }}
  {{ render_field(form.name, placeholder="git") }}
  {{ render_field(form.epoch, placeholder="0") }}
  {{ render_field(form.version, placeholder="2.32.0") }}
  {{ render_field(form.release, placeholder="1.fc36") }}
  {{ render_field(form.arch, placeholder="x86_64") }}

  <div class="form-group">
    <div class="col-sm-10 col-sm-offset-2">
      <button class="btn btn-primary" type="submit">
        <span class="glyphicon glyphicon-search"></span> Search
      </button>
    </div>
  </div>
</form>

{% if search_performed %}
  {% if results %}
    <table class="table table-striped table-bordered">
      <thead>
        <tr>
          <th>Project</th>
          <th>Build</th>
          <th>Chroot</th>
          <th>Name</th>
          <th>Epoch</th>
          <th>Version</th>
          <th>Release</th>
          <th>Arch</th>
        </tr>
      </thead>
      <tbody>
        {% for result in results %}
          {% set build = result.build_chroot.build %}
          {% set copr = build.copr %}
          <tr>
            <td>
              <a href="{{ copr_url('coprs_ns.copr_detail', copr) }}">
                {{ copr.full_name }}
              </a>
            </td>
            <td>
              <a href="{{ build_href(build) }}">{{ build.id }}</a>
            </td>
            <td>{{ result.build_chroot.name }}</td>
            <td>{{ result.name }}</td>
            <td>{{ result.epoch if result.epoch is not none else '-' }}</td>
            <td>{{ result.version }}</td>
            <td>{{ result.release }}</td>
            <td>{{ result.arch }}</td>
          </tr>
        {% endfor %}
      </tbody>
    </table>

    {% if paginator %}
      {{ render_pagination(request, paginator) }}
    {% endif %}
  {% else %}
    <p>No matching packages found.</p>
  {% endif %}
{% endif %}
{% endblock %}
