{%- extends "basic/layout.html" %}
{%- import "static/webpack-macros.html" as _webpack with context %}

{# Metadata and asset linking #}

{# Create the sidebar links HTML here to re-use in a few places #}
{# If we have no sidebar links, pop the links component from the sidebar list #}
{%- set sidebar_nav_html = generate_toctree_html("sidebar",
    show_nav_level=theme_show_nav_level|int,
    maxdepth=theme_navigation_depth|int,
    collapse=theme_collapse_navigation|tobool,
    includehidden=True,
    titles_only=True)
-%}


{# Remove the page-toc from secondary sidebar if there are no links to show #}
{% if generate_toc_html() | length < 1 %}
{% set theme_page_sidebar_items = theme_page_sidebar_items | reject("in", "page-toc.html") | list %}
{% endif %}

{# A flag for whether we include a secondary sidebar based on the page metadata #}
{% set remove_sidebar_secondary = (meta is defined and meta is not none
                                   and 'html_theme.sidebar_secondary.remove' in meta)
                                   or not theme_page_sidebar_items %}

{%- block css %}
  <script>
    document.documentElement.dataset.mode = localStorage.getItem("mode") || "{{ default_mode }}";
    document.documentElement.dataset.theme = localStorage.getItem("theme") || "light";
  </script>
  {{ _webpack.head_pre_assets() }}
  {{ _webpack.head_pre_icons() }}
  {{- css() }}
  {{ _webpack.head_js_preload() }}
{%- endblock %}

{%- block extrahead %}
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <meta name="docsearch:language" content="{{ language }}">
{%- endblock %}

{% block body_tag %}
  {# set up with scrollspy to update the toc as we scroll #}
  {# ref: https://getbootstrap.com/docs/4.0/components/scrollspy/ #}
  <body data-spy="scroll" data-target="#bd-toc-nav" data-offset="180" data-default-mode="{{ default_mode }}">
{%- endblock %}

{%- block content %}

  {# checkbox to toggle primary sidebar #}
  <input type="checkbox" class="sidebar-toggle" name="__primary" id="__primary">
  <label class="overlay overlay-primary" for="__primary"></label>

  {# Checkboxes to toggle the secondary sidebar #}
  <input type="checkbox" class="sidebar-toggle" name="__secondary" id="__secondary">
  <label class="overlay overlay-secondary" for="__secondary"></label>

  {# A search field pop-up that will only show when the search button is clicked #}
  <div class="search-button__wrapper">
    <div class="search-button__overlay"></div>
    <div class="search-button__search-container">
      {% include "../components/search-field.html" %}
    </div>
  </div>

  {%- if theme_announcement -%}
  <div class="bd-header-announcement container-fluid" id="header-announcement">
    {% include "sections/announcement.html" %}
  </div>
  {%- endif %}

  {% block docs_navbar %}
  <nav class="bd-header navbar navbar-expand-lg bd-navbar" id="navbar-main">
    {%- include "sections/header.html" %}
  </nav>
  {% endblock %}

  <div class="bd-container">
    <div class="bd-container__inner bd-page-width">
      {# Primary sidebar #}
      <div class="bd-sidebar-primary bd-sidebar">
        {% include "sections/sidebar-primary.html" %}
      </div>
      <main class="bd-main">
        {# Main content area #}
        {% block docs_main %}
        <div class="bd-content">
          <div class="bd-article-container">
            {# Article header #}
            <div class="bd-header-article">
                {% include "sections/header-article.html" %}
            </div>
            {# Article content #}
            {% block docs_body %}
            <article class="bd-article" role="main">
              {% block body %} {% endblock %}
            </article>
            {% endblock %}
            {# Article Footer #}
            {% if theme_show_prev_next %}
            <footer class="bd-footer-article">
                {% include "sections/footer-article.html" %}
            </footer>
            {% endif %}
          </div>
          {# Secondary sidebar #}
          {% block docs_toc %}
          {% if not remove_sidebar_secondary %}
            <div class="bd-sidebar-secondary bd-toc">
              {% include "sections/sidebar-secondary.html" %}
            </div>
          {% endif %}
          {% endblock %}
        </div>
        <footer class="bd-footer-content">
          <div class="bd-footer-content__inner">
            {% include "sections/footer-content.html" %}
          </div>
        </footer>
        {% endblock %}
      </main>
    </div>
  </div>

  {# Scripts placed at the end of the page to cut down on time to first content #}
  {%- block scripts_end %}
    {{ _webpack.body_post() }}
  {%- endblock %}

{%- endblock %}

{# Footer #}
{%- block footer %}
  <footer class="bd-footer">
    {%- include "sections/footer.html" %}
  </footer>
{%- endblock %}

{# Silence the sidebars and relbars since we define our own #}
{% block header %}{% endblock %}
{% block relbar1 %}{% endblock %}
{% block relbar2 %}{% endblock %}
{% block sidebarsourcelink %}{% endblock %}
