{% extends "base.html" %}
{% from 'partials/content-components.html' import article_card %}
{% from 'partials/navigation-components.html' import pagination %}

{% block content %}
{# Two-column layout similar to docs - tag navigation in sidebar #}
<div class="docs-layout">
  {# Left Sidebar: Tag Navigation #}
  <aside class="docs-sidebar" id="tag-sidebar" role="navigation" aria-label="Tag navigation">
    {% set current_tag = tag %}
    {% include 'partials/tag-nav.html' %}
  </aside>

  {# Main Content #}
  <div class="docs-main">
    {# Action Bar: Breadcrumbs + Share #}
    {% include 'partials/action-bar.html' %}

    <article class="prose">
      <header class="page-header">
        <h1>
          <span class="tag-icon">#</span>
          {{ tag }}
        </h1>

        <p class="page-description">
          {{ total_posts }} post{% if total_posts != 1 %}s{% endif %} tagged with "{{ tag }}"
        </p>
      </header>

      {% if posts %}
      <div class="archive-list">
        {% for post in posts %}
        {# Defensive: Skip autodoc pages (they shouldn't have tags, but just in case) #}
        {% set source_str = post.source_path | string %}
        {% if 'content/api' not in source_str and 'content/cli' not in source_str %}
        {{ article_card(post, show_excerpt=True) }}
        {% endif %}
        {% endfor %}
      </div>

      {# Pagination (if needed in future) #}
      {% if total_pages and total_pages > 1 %}
      {{ pagination(current_page, total_pages, base_url) }}
      {% endif %}
      {% else %}
      <p>No posts found with this tag.</p>
      {% endif %}

      <div class="tag-nav">
        <a href="{{ '/tags/' | absolute_url }}" class="button button-outline">← View all tags</a>
      </div>
    </article>
  </div>

  {# Right Sidebar: Empty for now (will be hidden by CSS, can add tag metadata later) #}
  <aside class="docs-toc"></aside>
</div>

{# styles moved to components/tags.css #}
{% endblock %}
