{% load static %}
{% load i18n %}
{% load l10n %}
{% load humanize %}
{% load mastodon %}
{% load duration %}
{% load thumb %}
<!DOCTYPE html>
<html lang="zh" class="classic-page nav-page-search">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{ site_name }} - {{ request.GET.q }} - {% trans 'Search Results' %}</title>
    {% include "common_libs.html" %}
  </head>
  <body>
    {% include '_header.html' %}
    <main>
      <div class="grid__main">
        <div>
          <div>
            {% if request.GET.q %}
              <hgroup>
                <h5>“{{ request.GET.q }}”</h5>
                <div>
                  {% visible_categories as cats %}
                  {% if request.GET.c and request.GET.c != 'all' %}
                    <a href="?q={{ request.GET.q }}&amp;c=all">{% trans "all" %}</a>
                  {% else %}
                    {% trans "all" %}
                  {% endif %}
                  {% if 'book' in cats %}
                    |
                    {% if request.GET.c != 'book' %}
                      <a href="?q={{ request.GET.q }}&amp;c=book">{% trans "books" %}</a>
                    {% else %}
                      {% trans "books" %}
                    {% endif %}
                  {% endif %}
                  {% if 'movie' in cats or 'tv' in cats %}
                    |
                    {% if request.GET.c != 'movietv' %}
                      <a href="?q={{ request.GET.q }}&amp;c=movietv">{% trans "movie & tv" %}</a>
                    {% else %}
                      {% trans "movie & tv" %}
                    {% endif %}
                  {% endif %}
                  {% if 'podcast' in cats %}
                    |
                    {% if request.GET.c != 'podcast' %}
                      <a href="?q={{ request.GET.q }}&amp;c=podcast">{% trans "podcasts" %}</a>
                    {% else %}
                      {% trans "podcasts" %}
                    {% endif %}
                  {% endif %}
                  {% if 'music' in cats %}
                    |
                    {% if request.GET.c != 'music' %}
                      <a href="?q={{ request.GET.q }}&amp;c=music">{% trans "music" %}</a>
                    {% else %}
                      {% trans "music" %}
                    {% endif %}
                  {% endif %}
                  {% if 'game' in cats %}
                    |
                    {% if request.GET.c != 'game' %}
                      <a href="?q={{ request.GET.q }}&amp;c=game">{% trans "games" %}</a>
                    {% else %}
                      {% trans "games" %}
                    {% endif %}
                  {% endif %}
                  {% if 'performance' in cats %}
                    |
                    {% if request.GET.c != 'performance' %}
                      <a href="?q={{ request.GET.q }}&amp;c=performance">{% trans "performances" %}</a>
                    {% else %}
                      {% trans "performances" %}
                    {% endif %}
                  {% endif %}
                </div>
              </hgroup>
            {% endif %}
            {% if request.GET.tag %}
              <h5>{% trans 'tag' %}: “{{ request.GET.tag }}”</h5>
            {% endif %}
            <div class="item-card-list">
              {% for item in items %}
                {% include '_list_item.html' with show_tags=1 %}
              {% empty %}
                <p>
                  {% trans "No items matching your search query." %}
                  {% if request.user.is_authenticated %}
                    {% trans "System will search other websites and instances, click title of the item to save them locally. " %}
                  {% endif %}
                </p>
                <p>
                  {% blocktrans %}If you have URL from one of these sites, please put the full URL (e.g. <code>https://www.imdb.com/title/tt2513074/</code>) to the search box and press Enter.{% endblocktrans %}
                  {% for site in sites %}
                    {% trans site %}
                    {% if not forloop.last %}/{% endif %}
                  {% endfor %}
                </p>
              {% endfor %}
            </div>
            {% if dup_items %}
              <p class="empty">
                {% blocktrans with dups=dup_items|length %} {{ dups }} items are from the same work or have the same identifier, they are hidden from the search results, <a _="on click toggle .unfold on #dup">click here to show them.</a> {% endblocktrans %}
              </p>
              <div class="item-card-list folded" id="dup">
                {% for item in dup_items %}
                  {% include '_list_item.html' with show_tags=1 %}
                {% endfor %}
              </div>
            {% endif %}
            <div class="item-card-list">
              {% if request.GET.q and request.user.is_authenticated %}
                <p hx-get="{% url 'catalog:external_search' %}?q={{ request.GET.q }}&amp;c={{ request.GET.c }}&amp;page={% if pagination.current_page %}{{ pagination.current_page }}{% else %}1{% endif %}"
                   hx-trigger="load"
                   hx-swap="outerHTML">
                  <span><i class="fa-solid fa-compact-disc fa-spin loading"></i></span>
                  {% trans 'Searching from other sites' %}
                </p>
              {% else %}
                {% trans "Logged in user may see search results from other sites." %}
              {% endif %}
            </div>
          </div>
          <div class="pagination">
            {% if pagination.has_prev %}
              <a href="?page=1&amp;{% if request.GET.q %}q={{ request.GET.q }}{% elif request.GET.tag %}tag={{ request.GET.tag }}{% endif %}{% if request.GET.c %}&c={{ request.GET.c }}{% endif %}"
                 class="pagination__nav-link pagination__nav-link">&laquo;</a>
              <a href="?page={{ pagination.previous_page }}&amp;{% if request.GET.q %}q={{ request.GET.q }}{% elif request.GET.tag %}tag={{ request.GET.tag }}{% endif %}{% if request.GET.c %}&c={{ request.GET.c }}{% endif %}"
                 class="pagination__nav-link pagination__nav-link--right-margin pagination__nav-link">&lsaquo;</a>
            {% endif %}
            {% for page in pagination.page_range %}
              {% if page == pagination.current_page %}
                <a href="?page={{ page }}&amp;{% if request.GET.q %}q={{ request.GET.q }}{% elif request.GET.tag %}tag={{ request.GET.tag }}{% endif %}{% if request.GET.c %}&c={{ request.GET.c }}{% endif %}"
                   class="pagination__page-link pagination__page-link--current">{{ page }}</a>
              {% else %}
                <a href="?page={{ page }}&amp;{% if request.GET.q %}q={{ request.GET.q }}{% elif request.GET.tag %}tag={{ request.GET.tag }}{% endif %}{% if request.GET.c %}&c={{ request.GET.c }}{% endif %}"
                   class="pagination__page-link">{{ page }}</a>
              {% endif %}
            {% endfor %}
            {% if pagination.has_next %}
              <a href="?page={{ pagination.next_page }}&amp;{% if request.GET.q %}q={{ request.GET.q }}{% elif request.GET.tag %}tag={{ request.GET.tag }}{% endif %}{% if request.GET.c %}&c={{ request.GET.c }}{% endif %}"
                 class="pagination__nav-link pagination__nav-link--left-margin">&rsaquo;</a>
              <a href="?page={{ pagination.last_page }}&amp;{% if request.GET.q %}q={{ request.GET.q }}{% elif request.GET.tag %}tag={{ request.GET.tag }}{% endif %}{% if request.GET.c %}&c={{ request.GET.c }}{% endif %}"
                 class="pagination__nav-link">&raquo;</a>
            {% endif %}
          </div>
        </div>
      </div>
      <aside class="grid__aside bottom">
        {% include "_sidebar_search.html" %}
      </aside>
    </main>
    {% include '_footer.html' %}
  </body>
</html>
