{#  -*- coding: utf-8 -*- #}
{% import 'base_helper.tmpl' as base with context %}

{% macro html_header() %}
    <header id="header">
        {{ html_site_title() }}
        {{ html_translation_header() }}
        {{ html_navigation_links() }}
        {% if search_form %}
            <div class="searchform" role="search">
                {{ search_form }}
            </div>
        {% endif %}
    </header>
    {{ template_hooks['page_header']() }}
{% endmacro %}

{% macro html_site_title() %}
    <h1 id="brand"><a href="{{ _link("root", None, lang) }}" title="{{ blog_title|e }}" rel="home">
    {% if logo_url %}
        <img src="{{ logo_url }}" alt="{{ blog_title|e }}" id="logo">
    {% endif %}

    {% if show_blog_title %}
        <span id="blog-title">{{ blog_title|e }}</span>
    {% endif %}
    </a></h1>
{% endmacro %}

{% macro html_navigation_links() %}
    <nav id="menu">
    <ul>
    {{ html_navigation_links_entries(navigation_links) }}
    {{ html_navigation_links_entries(navigation_alt_links) }}
    {{ template_hooks['menu']() }}
    {{ template_hooks['menu_alt']() }}
    </ul>
    </nav>
{% endmacro %}

{% macro html_navigation_links_entries(navigation_links_source) %}
    {% for url, text in navigation_links_source[lang] %}
        {% if isinstance(url, tuple) %}
            <li> {{ text }}
            <ul>
            {% for suburl, text in url %}
                {% if rel_link(permalink, suburl) == "#" %}
                    <li class="active"><a href="{{ permalink }}">{{ text }}<span class="sr-only"> {{ messages("(active)", lang) }}</span></a></li>
                {% else %}
                    <li><a href="{{ suburl }}">{{ text }}</a></li>
                {% endif %}
            {% endfor %}
            </ul>
        {% else %}
            {% if rel_link(permalink, url) == "#" %}
                <li class="active"><a href="{{ permalink }}">{{ text }}<span class="sr-only"> {{ messages("(active)", lang) }}</span></a></li>
            {% else %}
                <li><a href="{{ url }}">{{ text }}</a></li>
            {% endif %}
        {% endif %}
    {% endfor %}
{% endmacro %}

{% macro html_translation_header() %}
    {% if translations|length > 1 %}
        <div id="toptranslations">
            <h2>{{ messages("Languages:") }}</h2>
            {{ base.html_translations() }}
        </div>
    {% endif %}
{% endmacro %}
