{% load static %}
{% load i18n %}
{% load l10n %}
{% load humanize %}
{% load admin_url %}
{% load mastodon %}
{% load oauth_token %}
{% load truncate %}
{% load highlight %}
{% load thumb %}
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{ site_name }} - {% trans '搜索结果' %}</title>
    {% include "common_libs.html" with jquery=0 %}
</head>

<body>
    <div id="page-wrapper">
        <div id="content-wrapper">
            {% include 'partial/_navbar.html' %}

            <section id="content">
                <div class="grid">
                    <div class="grid__main">
                        <div class="main-section-wrapper">

                            <div class="entity-list">
                                {% if request.GET.q %}
                                <h5 class="entity-list__title">“{{ request.GET.q }}” {% trans '的搜索结果' %}</h5>
                                {% endif %}

                                {% if request.GET.tag %}
                                <h5 class="entity-list__title">{% trans '含有标签' %} “{{ request.GET.tag }}” {% trans '的结果' %}</h5>
                                {% endif %}

                                <ul class="entity-list__entities">
                                    {% for item in items %}
                                    {% with "list_item_"|add:item.class_name|add:".html" as template %}
                                    {% include template %}
                                    {% endwith %}
                                    {% empty %}
                                    <li class="entity-list__entity">
                                    {% trans '无站内条目匹配' %}
                                    </li>
                                    {% endfor %}
                                    {% if request.GET.q and user.is_authenticated %}
                                    <li class="entity-list__entity" hx-get="{% url 'catalog:external_search' %}?q={{ request.GET.q }}&c={{ request.GET.c }}&page={% if pagination.current_page %}{{ pagination.current_page }}{% else %}1{% endif %}" hx-trigger="load" hx-swap="outerHTML">
                                    {% trans '正在实时搜索站外条目' %}
                                    <div id="spinner">
                                        <div class="spinner">
                                            <div></div>
                                            <div></div>
                                            <div></div>
                                            <div></div>
                                            <div></div>
                                            <div></div>
                                            <div></div>
                                            <div></div>
                                            <div></div>
                                            <div></div>
                                            <div></div>
                                            <div></div>
                                        </div>
                                    </div>
                                    </li>
                                    {% endif %}
                                </ul>
                            </div>
                            <div class="pagination" >

                                {% if pagination.has_prev %}
                                    <a href="?page=1&{% 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 }}&{% 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 }}&{% 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 }}&{% 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 }}&{% 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 }}&{% 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>

                    {% include "search_sidebar.html" %}
                </div>
            </section>
        </div>
        {% include 'partial/_footer.html' %}
    </div>



    <script>
      document.body.addEventListener('htmx:configRequest', (event) => {
        event.detail.headers['X-CSRFToken'] = '{{ csrf_token }}';
      })
    </script>
</body>


</html>
