{% extends "./browse.html" %}

{% comment %}
Copyright (C) 2017-2026  The Software Heritage developers
See the AUTHORS file at the top-level directory of this distribution
License: GNU Affero General Public License version 3, or any later version
See top-level LICENSE file for more information
{% endcomment %}

{% load static %}

{% block navbar-content %}
  <h4>Search archived software</h4>
{% endblock navbar-content %}

{% block browse-content %}
  {% include "./includes/origin-search-form.html" %}
  <hr />
  <div id="swh-origin-search-results"
       class="mb-3"
       {% if total_results < 0 %}style="display: none;"{% endif %}>
    <div class="table-responsive">
      <div id="swh-origin-search-total-results" class="float-end">
        {% if total_results >= 0 %}{{ total_results }} origins found{% endif %}
      </div>
      <table class="table swh-table swh-table-striped js-only"
             id="origin-search-results">
        <thead>
          <tr>
            <th>Origin type</th>
            <th>Origin url</th>
            <th>Archiving status</th>
          </tr>
        </thead>
        <tbody>
        </tbody>
      </table>
      <noscript>
        <table class="table swh-table swh-table-striped"
               id="origin-search-results-no-js">
          <thead>
            <tr>
              <th>Origin type</th>
              <th>Origin url</th>
              <th>Archiving status</th>
            </tr>
          </thead>
          <tbody>
            {% for origin in origins %}
              {% for visit_type in origin.visit_types %}
                <tr class="swh-search-result-entry swh-tr-hover-highlight">
                  <td class="swh-origin-visit-type" style="width: 120px;">{{ visit_type }}</td>
                  <td style="white-space: nowrap;">
                    <a href="{% url 'browse-origin' %}?origin_url={{ origin.url|iriencode }}&visit_type={{ visit_type }}">
                      {{ origin.url }}
                    </a>
                  </td>
                  <td class="swh-visit-status">
                    {% if 'snapshot_id' in origin and origin.snapshot_id %}
                      <i title="Software origin has been archived by Software Heritage"
                         class="mdi mdi-check-bold mdi-fw"></i>Archived
                    {% elif 'snapshot_id' in origin and origin.snapshot_id is None %}
                      <i title="Software origin archival by Software Heritage is pending"
                         class="mdi mdi-close-thick mdi-fw"></i>Pending archival
                    {% else %}
                      ???
                    {% endif %}
                  </td>
                </tr>
              {% endfor %}
            {% endfor %}
          </tbody>
        </table>
      </noscript>
    </div>
  </div>
  <div class="swh-loading js-only">
    <img src="{% static 'img/swh-spinner.gif' %}" alt="swh spinner" />
    <p>Searching origins ...</p>
  </div>
  <p id="swh-no-result"
     class="js-only"
     style="display: none;
            white-space: pre">
    <br />
    No origins matching the search criteria were found.
  </p>
  <ul class="pagination justify-content-center swh-search-pagination js-only">
    <li class="disabled page-item" id="origins-prev-results-button">
      <a class="page-link" href="#" tabindex="-1">Previous</a>
    </li>
    <li class="disabled page-item" id="origins-next-results-button">
      <a class="page-link" href="#" tabindex="-1">Next</a>
    </li>
  </ul>
  <noscript>
    <ul class="pagination justify-content-center swh-search-pagination">
      <li class="page-item {% if not previous_page_url %}disabled{% endif %}">
        <a class="page-link" href="{{ previous_page_url }}" tabindex="-1">Previous</a>
      </li>
      <li class="page-item {% if not next_page_url %}disabled{% endif %}">
        <a class="page-link" href="{{ next_page_url }}" tabindex="-1">Next</a>
      </li>
    </ul>
  </noscript>
  <script>swh.webapp.initPage('search');</script>
{% endblock browse-content %}
