{% extends "layout.html" %}

{% import "snippets.html" as snippets with context %}
{% import "utils.html" as utils with context %}

{% set logo = snippets.logo() %}
{% set before_header = snippets.before_header() %}
{% set after_header = snippets.after_header() %}
{% set before_footer = snippets.before_footer() %}
{% set after_footer = snippets.after_footer() %}
{% set license_info = snippets.license_info() %}
{% set creditlogos = snippets.creditlogos() %}
{% set credits = snippets.credits() %}

{% block layout %}
    <div id="moin-main-wrapper">
        {{ before_header }}
        <header id="moin-header" lang="{{ theme_supp.user_lang }}" dir="{{ theme_supp.user_dir }}">
            {% block header %}
                <div id="moin-header-top">
                    <div id="moin-logo-sitename">
                        {% if logo %}
                            <div id="moin-logo">
                                <a href="{{ url_for('frontend.show_item', item_name=cfg.root_mapping.get('', cfg.default_root)) }}">{{ logo }}</a>
                            </div>
                        {% endif %}
                        {% if cfg.sitename %}
                            <a class="moin-sitename" href="{{ url_for('frontend.show_item', item_name=cfg.default_root) }}">
                                {{ cfg.sitename }}
                            </a>
                        {% endif %}
                    </div>
                    <button type="button" id="toggle-header" title="Toggle menu" class="navbar-toggle">
                        <i class="fa fa-bars"></i>
                    </button>
                </div>
                <div id="moin-username">
                    {%- if user.valid -%}
                        {%- set avatar = user.avatar(20) %}
                        {%- if avatar %}
                            <div>
                                <img id="moin-avatar" src="{{ avatar }}" />
                            </div>
                        {%- endif %}
                        {% if user.name -%}
                            {%- set wiki_href, display_name, title, exists = theme_supp.userhome() %}
                            <div>
                                <a href="{{ wiki_href }}" {% if not exists %}class="moin-nonexistent"{% endif %} rel="nofollow" title="{{ title }}">
                                    <i class="fa fa-user"></i>
                                    <span>{{ display_name }}</span>
                                </a>
                            </div>
                            {%- if 'frontend.usersettings' not in cfg.endpoints_excluded -%}
                                <div>
                                    <a href="{{ url_for('frontend.usersettings') }}" class="moin-usersettings" rel="nofollow" title="{{ _('Settings') }}">
                                        <i class="fa fa-cog"> </i>
                                        <span>{{ _('Settings') }}</span>
                                    </a>
                                </div>
                            {%- endif %}
                        {%- endif %}
                        {%- if user.auth_method in cfg.auth_can_logout %}
                            <div>
                                <a href="{{ url_for('frontend.logout', logout_submit=1) }}" class="moin-logout" rel="nofollow" title="{{ _('Logout') }}">
                                    <i class="fa fa-sign-out"> </i>
                                    <span>{{ _('Logout') }}</span>
                                </a>
                            </div>
                        {%- endif %}
                    {%- else %}
                        {%- set login_url = theme_supp.login_url() %}
                        {%- if login_url %}
                            <div>
                                <a href="{{ login_url }}" class="moin-login" rel="nofollow" title="{{ _('Login') }}">
                                    <i class="fa fa-sign-in"> </i>
                                    <span>{{ _('Login') }}</span>
                                </a>
                            </div>
                        {%- endif %}
                    {%- endif %}
                </div>
                {% set navibar_items = theme_supp.navibar(fqname) %}
                {% if search_form %}
                    {{ header_search(search_form) }}
                {% endif %}

                <!-- Breadcrumb - Start -->
                {#
                Produce a page trail given a list of recently visited items,
                and an optional title_name (means current view is a Navigation Link: History, Index, Tags...).
                    - if an item has alias names, all alias names must be provided (themes can show, suppress or provide a rollover action)
                    - if an item is not in the default namespace, the namespace will be prefixed to the item name
                    - last item on page trail must show individual links to all parent items
                #}
                <div class="moin-breadcrumb">
                    <div class="moin-panel-heading"><i>{{ _('Page Trail') }}</i></div>
                    {%- set trail_items = theme_supp.path_breadcrumbs() %}
                    {%- if trail_items %}
                        <ul>
                            {%- for wiki_name, fqname, item_href, aliases, err in trail_items %}
                                {%- if not loop.last %}
                                    <li>
                                        {{ utils.page_trail_link(wiki_name, fqname) }}
                                        {{ utils.alias_list(aliases) }}
                                    </li>
                                {%- endif %}
                                {%- if loop.last %}
                                    <li>
                                        {%- for segment_name, segment_path in theme_supp.location_breadcrumbs(fqname) -%}
                                            {%- if not loop.last %}
                                                <a href="{{ url_for('frontend.show_item', item_name=segment_path) }}" {%- if not exists -%}class="moin-nonexistent"{%- endif -%}>
                                                    {{ segment_name|shorten_fqname }}
                                                </a>
                                            {%- else %}
                                                <a href="{{ url_for('frontend.show_item', item_name=segment_path) }}" {% if not exists %}class="moin-nonexistent"{% endif %}>
                                                    {{ segment_name|shorten_fqname }}
                                                </a>
                                            {%- endif %}
                                        {%- endfor %}
                                        {{ utils.alias_list(aliases) }}
                                    </li>
                                    {%- if title_name %}
                                        <div>
                                            {{ title_name }}
                                        </div>
                                    {%- endif %}
                                {%- endif %}
                            {%- endfor %}
                        </ul>
                    {%- endif %}
                </div>
                <!-- Breadcrumb - End -->

                {% if navibar_items %}
                    <div id="moin-navibar" class="panel" data-expanded_quicklinks_size="{{ cfg.expanded_quicklinks_size }}">
                        {% for cls, url, text, title, iconcls in navibar_items %}
                            <div class="{{ cls }}">
                                <a href="{{ url }}" {% if title %}title="{{ title }} : {{ url|safe }}"{% else %}title="{{ url|safe }}"{% endif %}>
                                    <i class="{{ iconcls }}"></i>
                                    <span>{{ text }}</span>
                                </a>
                            </div>
                        {% endfor %}
                    </div>
                {% endif %}

            {% endblock %}
        </header>
        {{ after_header }}

        <div id="moin-page" role="main" lang="{{ theme_supp.content_lang }}" dir="{{ theme_supp.content_dir }}">
            {% block header_itemviews %}{% endblock %}

            {% block item -%}
                <div id="moin-content">
                    <div id="moin-flash">  {# client side javascript may add messages here #}
                        {% for category, msg in get_flashed_messages(with_categories=true) %}
                            <p class="moin-flash moin-flash-{{ category }}">{{ msg }}</p>
                        {% endfor %}
                    </div>
                    {% block content %}
                        {# All content templates should have implement this block. #}
                    {% endblock %}
                </div>
            {%- endblock %}

            {{ before_footer }}
            <footer id="moin-footer">
                {% block footer %}
                    {% block footer_hr %}{% endblock %}
                    {% block footer_meta %}{% endblock %}
                    <div id="moin-credits-container">
                        {{ credits }}
                        {{ creditlogos }}
                    </div>
                    {{ license_info }}
                {% endblock %}
            </footer>
            {{ after_footer }}
        </div>


    </div>
{% endblock %}

{% block body_scripts %}
    {{ super() }}
    <script src="/_themes/focus/js/main.js"></script>
{% endblock %}
