{#
================================================================================
Navigation Menu Macros - REFERENCE ONLY
================================================================================
NOTE: These macros are now defined INLINE in base.html because Jinja2's
{% from ... import %} doesn't work with template inheritance - child templates
that extend base.html don't inherit the imported macros.

This file is kept as documentation/reference for the macro signatures.
The actual macros are defined at the top of base.html.

See: plan/active/rfc-template-performance-optimization.md
================================================================================
#}

{#
Render manual menu items from config.

Args:
    menu: List of menu item dicts from get_menu_lang()
    is_mobile: If true, adds 'has-submenu' class for mobile styling
#}
{% def render_menu_items(menu, is_mobile=false) %}
{% if menu %}
{% spaceless %}
{% for item in menu %}
<li class="{{ 'has-submenu' if (is_mobile and item.children) else '' }} {{ 'active' if item.active else '' }} {{ 'active-trail' if (not is_mobile and item.active_trail) else '' }}">
    <a href="{{ item.href | absolute_url }}">{{ item.name }}</a>
    {% if item.children %}
    <ul class="submenu">
        {% for child in item.children %}
        <li class="{{ 'active' if child.active else '' }}">
            <a href="{{ child.href | absolute_url }}">{{ child.name }}</a>
        </li>
        {% end %}
    </ul>
    {% end %}
</li>
{% end %}
{% end %}
{% end %}
{% end %}

{#
Render auto-discovered navigation items.

Args:
    auto_nav: List of auto-discovered nav items from get_auto_nav()
    page_url: Current page URL for active state detection
#}
{% def render_auto_nav(auto_nav, page_url) %}
{% if auto_nav %}
{# Always show Home first in auto mode #}
<li class="{{ 'active' if page_url == '/' else '' }}">
    <a href="{{ '/' | absolute_url }}">Home</a>
</li>
{% for item in auto_nav %}
<li class="{{ 'active' if (page_url is string and item._path is string and page_url.startswith(item._path) and item._path != '/') else '' }}">
    <a href="{{ item.href | absolute_url }}">{{ item.name }}</a>
</li>
{% end %}
{% end %}
{% end %}

{#
Render GitHub link if configured and not bundled in Dev menu.

Args:
    site: Site object with config
    is_mobile: If true, uses mobile styling with inline SVG margin
#}
{% def render_github_link(site, is_mobile=false) %}
{% set github_bundled = false %}
{% if site._dev_menu_metadata %}
{% set github_bundled = site._dev_menu_metadata.get("github_bundled", false) %}
{% end %}
{% if config.params and config.params.repo_url and not github_bundled %}
<li>
    {% if is_mobile %}
    <a href="{{ config.params.repo_url }}" target="_blank" rel="noopener">
        {{ icon('github-logo', size=16, css_class='nav-icon') }}
        GitHub
    </a>
    {% else %}
    <a href="{{ config.params.repo_url }}" target="_blank" rel="noopener"
        title="GitHub Repository" data-external="true" aria-label="GitHub (opens in new tab)">
        {{ icon('github-logo', size=16) }}
        <span>GitHub</span>
    </a>
    {% end %}
</li>
{% end %}
{% end %}

{#
Render logo/brand element.

Args:
    site: Site object with config
    site_title: Pre-cached site title
#}
{% def render_logo(site, site_title) %}
{% set _logo_image = site.logo_image or site.logo %}
{% set _logo_text = site.logo_text or site.title %}
{% if _logo_image %}
<img src="{{ _logo_image | absolute_url }}" alt="{{ site_title }}" class="brand-image" />
{% elif _logo_text %}
<span class="brand-text">{{ _logo_text }}</span>
{% else %}
<span class="brand-text">{{ site_title }}</span>
{% end %}
{% end %}
