<!DOCTYPE html>

    {% include 'partials/head.html' %}
	{% include 'partials/header.html' %}
	{% include 'partials/video.html' %}

<div class="main-page">
    <div class="middle-content">
        <div class="body-content">
            <div class="title-content"><h1>Buscar en el foro</h1></div>
            <div class="box-content">
                <div class="body-box-content">
                    {% include 'forum/_style.html' %}
                    <div class="forum-wrap">
                        <form class="forum-search" action="{% url 'forum_search' %}" method="GET" style="margin-bottom:16px">
                            <input type="text" name="q" value="{{ query }}" placeholder="Buscar en el foro..."
                                   style="width:70%;background:rgba(0,0,0,.3);color:#e8e0d0;border:1px solid rgba(215,150,2,.4);padding:8px;border-radius:3px">
                            <button type="submit" class="forum-btn">Buscar</button>
                        </form>

                        {% if query %}
                            <p style="color:#b1997f">Resultados para «{{ query }}»: {{ results|length }}</p>
                            {% for topic in results %}
                            <div class="topic-row">
                                <div class="main">
                                    <a class="name" href="{% url 'forum_topic_p1' topic_id=topic.id %}">{{ topic.name }}</a>
                                    <div class="desc">en {{ topic.forum_name }} · por {{ topic.display_poster }} · {{ topic.created }}</div>
                                </div>
                            </div>
                            {% empty %}
                            <p>No se encontraron temas.</p>
                            {% endfor %}

                            {% if pagination and pagination.total_pages > 1 %}
                            <div class="forum-pagination">
                                {% if pagination.has_prev %}<a href="?q={{ query|urlencode }}&page={{ pagination.prev_page }}">« Anterior</a>{% endif %}
                                {% for p in pagination.page_range %}
                                    {% if p == pagination.page %}<span class="current">{{ p }}</span>
                                    {% else %}<a href="?q={{ query|urlencode }}&page={{ p }}">{{ p }}</a>{% endif %}
                                {% endfor %}
                                {% if pagination.has_next %}<a href="?q={{ query|urlencode }}&page={{ pagination.next_page }}">Siguiente »</a>{% endif %}
                            </div>
                            {% endif %}
                        {% else %}
                            <p>Escribe al menos 2 caracteres para buscar.</p>
                        {% endif %}

                        <div class="forum-actions" style="margin-top:16px">
                            <a class="forum-btn" href="{% url 'app_forum' %}">← Volver al foro</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

	{% include 'partials/social.html' %}
	{% include 'partials/footer.html' %}
	{% include 'partials/final.html' %}
