{% extends "base.html" %}

{#
CLI Reference List Template

Three-column layout optimized for CLI documentation section index pages:
- Left sidebar: Navigation tree
- Center: Content + Child page tiles
- Right sidebar: TOC + metadata

Usage: Set `template: autodoc/cli/list.html` in frontmatter
Or set `type: autodoc-cli` to auto-select this template

Features:
- Automatically displays child pages and subsections as tiles
- Disable with `show_children: false` in frontmatter
#}

{% from 'partials/navigation-components.html' import breadcrumbs, page_navigation, toc %}
{% from 'partials/components/tags.html' import tag_list %}
{% from 'partials/components/tiles.html' import content_tiles %}

{% block content %}
{# Ensure page is set - use section.index_page if page not defined #}
{# This is needed for breadcrumbs, sidebar navigation, and content rendering #}
{% if not page and section %}
  {% set page = section.index_page %}
{% end %}

{# Three-column documentation layout #}
<div class="docs-layout">
    {# Left Sidebar: Navigation #}
    <aside class="docs-sidebar" id="docs-sidebar" role="navigation" aria-label="CLI navigation">
        {% include 'partials/docs-nav.html' %}
    </aside>

  {# Main Content #}
  <div class="docs-main">
    {# Page Hero: Breadcrumbs + Title + Description #}
    {% set _list_hero_default = 'overview' %}
    {% include 'partials/page-hero.html' %}

    {# Article Content - flattened structure #}
    <article class="prose docs-content {% if page and params.css_class %}{{ params.css_class }}{% end %}">
      {{ content | safe }}

      {# Content tiles with smart defaults - use discover: frontmatter to customize #}
      {% set discover = params.discover %}
      {% set children_config = discover.children %}
      {% set related_config = discover.related %}

      {% set children_disabled = children_config is sameas false %}
      {% set related_disabled = related_config is sameas false %}
      {% set show_children_feature = 'content.children' in theme.features %}
      {% set show_children = (not children_disabled) and show_children_feature %}
      {% set show_related = not related_disabled %}

      {% set children_title = children_config.title ?? 'In This Section' %}
      {% set children_variant = children_config.variant ?? 'compact' %}
      {% set related_title = related_config.title ?? 'Related Pages' %}
      {% set related_limit = related_config.limit ?? 5 %}

      {% set children_title = none if children_title is sameas false else children_title %}
      {% set related_title = none if related_title is sameas false else related_title %}

      {% set has_children = posts or subsections %}
      {% set has_related = show_related and page and page.related_posts %}

      {% if show_children and (has_children or has_related) %}
      <div class="docs-children">
        {{ content_tiles(
          title=children_title if has_children else none,
          children=posts if show_children else none,
          subsections=subsections if show_children else none,
          related=page.related_posts[:related_limit] if has_related else none,
          related_title=related_title,
          variant=children_variant,
          group_by='type' if has_children and has_related else none,
          page=page
        ) }}
      </div>
      {% end %}

      {# Tags #}
      {% if page and page.tags %}
      <footer class="docs-footer">
        {{ tag_list(page.tags) }}
      </footer>
      {% end %}
    </article>

    {# Page navigation (prev/next) at bottom #}
    {{ page_navigation(page) }}
  </div>

  {# Right Sidebar: TOC + Metadata #}
  {% if toc_items %}
  <aside class="docs-toc" role="complementary" aria-label="Table of contents">
    {{ toc(toc_items=toc_items, toc=toc, page=page) }}
  </aside>
  {% end %}
</div>

{# Mobile sidebar toggle button #}
<button class="docs-sidebar-toggle" aria-label="Toggle navigation sidebar" aria-expanded="false"
  aria-controls="docs-sidebar">
  {{ icon('list', size=20) }}
</button>

{# Sidebar overlay for mobile #}
<div class="docs-sidebar-overlay" aria-hidden="true"></div>
{% end %}

{# Sidebar toggle functionality is handled by interactive.js #}
