{% extends "base.html" %}

{% set active_tab = '' %}

{% block title %}Second Brain - All Pages{% endblock %}

{% block content %}
<div class="page-header">
    {% if query %}
    <h1>Search Results for "{{ query }}"</h1>
    <p>{{ pages | length }} result{{ 's' if pages | length != 1 }}</p>
    {% else %}
    <h1>All Pages</h1>
    <p>{{ pages | length }} page{{ 's' if pages | length != 1 }}</p>
    {% endif %}
    {% if tag_filter %}
    <span class="filter-badge">
        Filtering: <strong>{{ tag_filter }}</strong>
        <a href="/" class="clear-filter">✕ Clear</a>
    </span>
    {% endif %}
</div>

{% if pages %}
<div class="pages">
    {% for page in pages %}
    <div class="page-card">
        <div class="page-card-content">
            <h3 class="page-title">
                <a href="/wiki/{{ page.slug }}">{{ page.title }}</a>
            </h3>

            {% if page.snippet %}
            <p class="page-snippet">{{ page.snippet }}</p>
            {% endif %}

            <div class="page-meta">
                {% if page.tags %}
                {% for tag in page.tags.split(',') %}
                {% if tag.strip() %}
                <a href="?tag={{ tag.strip() | urlencode }}" class="tag">{{ tag.strip() }}</a>
                {% endif %}
                {% endfor %}
                {% endif %}

                {% if page.updated %}
                <span class="date">Updated {{ page.updated }}</span>
                {% endif %}
            </div>
        </div>
    </div>
    {% endfor %}
</div>
{% else %}
<div class="empty-state">
    <svg class="empty-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor">
        <path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/>
        <polyline points="14 2 14 8 20 8"/>
        <line x1="16" y1="13" x2="8" y2="13"/>
        <line x1="16" y1="17" x2="8" y2="17"/>
        <polyline points="10 9 9 9 8 9"/>
    </svg>
    <h3>No pages found</h3>
    <p>Your wiki is empty or no results match.</p>
    {% if query or tag_filter %}
    <a href="/" class="btn">Clear</a>
    {% endif %}
</div>
{% endif %}
{% endblock %}