{%comment%}<!--
  Copyright (c) 2016-2021 Martin Donath <martin.donath@squidfunk.com>

  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to
  deal in the Software without restriction, including without limitation the
  rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  sell copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  IN THE SOFTWARE.
-->{%endcomment%}

{% assign lang = site.data.languages[page.language] %}
<input class=md-toggle data-md-toggle=drawer type=checkbox id=__drawer autocomplete=off>
{% unless page.disable_search %}
<input class=md-toggle data-md-toggle=search type=checkbox id=__search autocomplete=off>
{% endunless %}
<label class=md-overlay data-md-component=overlay for=__drawer></label> <a href="#{{ page.title | slugify }}" tabindex=1
                                                                           class=md-skip> Skip to content </a>
<header class=md-header data-md-component=header>
    <nav
            class="md-header__inner md-grid"
            aria-label="{{ lang['header.title'] }}"
    >

        <!-- Link to home -->
    <a
            href="{{ site.url }}"
            title="{{ site.title }}"
            class="md-header__button md-logo"
            aria-label="{{ site.title }}"
            data-md-component="logo"
    >
        {% include logo.html %}
    </a>

        <!-- Button to open drawer -->
        <label class="md-header__button md-icon" for="__drawer">
            {% include .icons/material/menu.svg %}
        </label>

        <!-- Header title -->
        <div class="md-header__title" data-md-component="header-title">
            <div class="md-header__ellipsis">
                <div class="md-header__topic">
                    <span class="md-ellipsis">
                    {{ site.title }}
                    </span>
                </div>
                <div class="md-header__topic" data-md-component="header-topic">
                    <span class="md-ellipsis">
                    {{ page.title }}
                    </span>
                </div>
            </div>
        </div>


        <!-- Color palette -->
        {% if site.theme_palette.options %}
        <form class="md-header__option" data-md-component="palette">
            {% for idx in (0..config.theme.palette.options.size) %}
            {% assign option = config.theme.palette.options[idx] %}
            {% assign primary = option.primary | replace: " ", "-" | lower %}
            {% assign accent  = option.accent  | replace: " ", "-" | lower %}
            <input
                    class="md-option"
                    data-md-color-media="{{ option.media }}"
                    data-md-color-scheme="{{ option.scheme }}"
                    data-md-color-primary="{{ primary }}"
                    data-md-color-accent="{{ accent }}"
                    type="radio"
                    name="__palette"
                    id="__palette_{{ loop.index }}"
            />
            {% if option.toggle %}
            <label
                    class="md-header__button md-icon"
                    title="{{ option.toggle.name }}"
                    for="__palette_{{ idx }}"
                    hidden
            >
                {% capture icon %}.icons/{{option.toggle.icon}}.svg{% endcapture %}
                {%comment%}{% include {{ icon }} %}{%endcomment%}
            </label>
            {% endif %}
            {% endfor %}
        </form>
        {% endif %}


        <!-- Site language selector -->
        {% if site.extra.alternate %}
        <div class="md-header__option">
            <div class="md-select">
                {% if site.theme_icon.alternate %}
                {% assign icon = config.theme.icon.alternate %}
                {% else %}
                {% assign icon = "material/translate" %}
                {% endif %}
                <button class="md-header__button md-icon">
                    {% capture icon %}.icons/{{icon}}.svg{% endcapture %}
                    {%comment%}{% include {{icon}} %}{%endcomment%}
                </button>
                <div class="md-select__inner">
                    <ul class="md-select__list">
                        {% for alt in site.extra.alternate %}
                        <li class="md-select__item">
                            <a
                                    href="{{site.baseurl}}/{{ alt.link }}"
                                    hreflang="{{ alt.lang }}"
                                    class="md-select__link"
                            >
                                {{ alt.name }}
                            </a>
                        </li>
                        {% endfor %}
                    </ul>
                </div>
            </div>
        </div>
        {% endif %}

        <!-- Button to open search modal -->
        {% unless page.disable_search %}
            <label class="md-header__button md-icon" for="__search">
                {% include .icons/material/magnify.svg %}
            </label>

            <!-- Search interface -->
            {% include search.html %}
        {% endunless %}

        <!-- Repository information -->
        {% if site.repo_url %}
        <div class="md-header__source">
            {% include source.html %}
        </div>
        {% endif %}
    </nav>
</header>
