{% extends "base.html" %}

{#
API Reference Home Template

Optimized home page template for API reference sites. Features:
- No action bar (cleaner for home page)
- Hero section with title and description
- Main content area
- Quick links to key API reference sections
- No blog posts (API reference sites don't need recent posts)

Usage: Set `type: autodoc-python` on home page to auto-select
Or set `template: autodoc/python/home.html` in frontmatter
#}

{% block content %}
<div class="docs-home">
    {# Hero Section #}
    <header class="docs-home-hero">
        <div class="docs-home-hero-content">
            <h1 class="docs-home-title">{{ page.title | default(site.title) }}</h1>
            {% if params.description %}
            <p class="docs-home-subtitle">{{ params.description }}</p>
            {% end %}
        </div>
    </header>

    {# Main Content #}
    {% if content and content.strip() %}
    <div class="docs-home-content prose">
        {{ content | safe }}
    </div>
    {% end %}

    {# Quick Links to Key Sections #}
    {% set show_quick_links = params.show_quick_links ?? true %}
    {% if show_quick_links %}
    {# Find API reference sections #}
    {% set api_sections = [] %}
    {% for section in site.sections %}
    {% if section.metadata.type == 'autodoc-python' or section.metadata.content_type == 'autodoc-python' %}
    {% set _ = api_sections.append(section) %}
    {% end %}
    {% end %}

    {# If no autodoc-python sections found, try common section names #}
    {% if not api_sections %}
    {% set common_names = ['api', 'autodoc-python', 'api-docs', 'reference'] %}
    {% for name in common_names %}
    {% set candidates = site.sections | selectattr('name', 'equalto', name) | list %}
    {% if candidates %}
    {% set _ = api_sections.append(candidates[0]) %}
    {% end %}
    {% end %}
    {% end %}

    {% if api_sections %}
    {# Build sortable list with safe weight values #}
    {% set sortable_sections = [] %}
    {% for section in api_sections %}
    {% set _weight = section.metadata.weight %}
    {% set _ = sortable_sections.append({'section': section, 'weight': _weight or 999999}) %}
    {% end %}
    <section class="docs-home-sections">
        <h2 class="docs-home-sections-title">{{ page.title ?? 'API Reference' }} Sections</h2>
        <div class="docs-home-sections-grid">
            {% for item in sortable_sections | sort(attribute='weight') | limit(6) %}
            {% set section = item.section %}
            <a href="{{ section.href }}" class="docs-home-section-card gradient-border fluid-combined">
                <h3 class="docs-home-section-title">{{ section.title }}</h3>
                {% if section.metadata.description %}
                <p class="docs-home-section-description">{{ section.metadata.description }}</p>
                {% end %}
                {% if section.pages %}
                <span class="docs-home-section-count">{{ section.pages | length }} module{{ 's' if section.pages |
                    length
                    != 1 else '' }}</span>
                {% end %}
            </a>
            {% end %}
        </div>
    </section>
    {% end %}
    {% end %}

    {# Custom Quick Links from metadata #}
    {% if params.quick_links %}
    <section class="docs-home-quick-links">
        <h2 class="docs-home-quick-links-title">Quick Links</h2>
        <div class="docs-home-quick-links-grid">
            {% for link in params.quick_links %}
            <a href="{{ link.href or link.url }}" class="docs-home-quick-link-card gradient-border">
                {% if link.icon %}
                <div class="docs-home-quick-link-icon">{{ link.icon }}</div>
                {% end %}
                <h3>{{ link.title }}</h3>
                {% if link.description %}
                <p>{{ link.description }}</p>
                {% end %}
            </a>
            {% end %}
        </div>
    </section>
    {% end %}
</div>
{% end %}
