{% extends "base/base.html" %}

{% block custom_css %}
<style>
  :root {
    --header-background: {{ header_background or "var(--design-primary-color, var(--panel-primary-color))" }};
    --header-color: {{ header_color or "var(--design-primary-text-color, var(--panel-on-primary-color))" }};
    --sidebar-width: {{ sidebar_width }}px;
  }
  #header {
    --background-color: var(--header-background);
    --text-color: var(--header-color);
    --design-background-text-color: var(--header-color);
    --design-background-color: var(--header-background);
    background-color: var(--header-background);
    color: var(--header-color);
    {% if theme._name == 'default' %}
    box-shadow: 5px 5px 20px silver;
    {% endif %}
  }
  #sidebar {
    width: var(--sidebar-width);
  }
</style>
{% endblock %}

<!-- goes in body -->
{% block contents %}
<div id="container">
  {% block header %}
  <nav id="header">
    {% if nav %}
    <span onclick="{{ 'openNav()' if collapsed_sidebar else 'closeNav()' }}" id="sidebar-button">
      <div class="pn-bar"></div>
      <div class="pn-bar"></div>
      <div class="pn-bar"></div>
    </span>
    {% endif %}
    <div class="app-header">
      {% if app_logo %}
      <a href="{{ site_url }}">
	<img src="{{ app_logo }}" class="app-logo"></img>
      </a>
      {% endif %}
      {% if site_title %}
      <a class="title" href="{{ site_url }}" >&nbsp;{{ site_title }}</a>
      {% endif %}
      {% if site_title and app_title%}
      <span class="title">-</span>
      {% endif %}
      {% if app_title %}
      <a class="title" href="" >&nbsp;{{ app_title }}</a>
      {% endif %}
    </div>
    <div id="header-items">
    {% for doc in docs %}
    {% for root in doc.roots %}
    {% if "header" in root.tags %}
    {{ embed(root) | indent(8) }}
    {% endif %}
    {% endfor %}
    {% endfor %}
    </div>
    {% block header_end %}
    {% endblock %}
    {% if busy %}
    <div class="pn-busy-container">
      {{ embed(roots.busy_indicator) | indent(6) }}
    </div>
    {% endif %}
  </nav>
  {% endblock %}

  {% block content %}
  <div id="content">
    {% if nav %}
    <div class="sidenav {{'hidden' if collapsed_sidebar else ''}}" id="sidebar">
      <ul class="nav flex-column">
        {% for doc in docs %}
        {% for root in doc.roots %}
        {% if "nav" in root.tags %}
          {{ embed(root) | indent(8) }}
        {% endif %}
        {% endfor %}
        {% endfor %}
      </ul>
    </div>
    {% endif %}

    {% block main %}
    <div class="main" id="main">
      {% if main_max_width %}
      <div style="margin-left: auto; margin-right: auto; max-width: {{main_max_width}}">
      {% endif %}
      {% for doc in docs %}
      {% for root in doc.roots %}
      {% if "main" in root.tags %}
      {{ embed(root) | indent(4) }}
      {% endif %}
      {% endfor %}
      {% endfor %}
      {% if main_max_width %}
      </div>
      {% endif %}

      <div id="pn-Modal" class="pn-modal header-adjust">
	<div class="pn-modal-content">
	  <span class="pn-modalclose" id="pn-closeModal">&times;</span>
	  {% for doc in docs %}
	  {% for root in doc.roots %}
	  {% if "modal" in root.tags %}
	  {{ embed(root) | indent(10) }}
	  {% endif %}
	  {% endfor %}
	  {% endfor %}
	</div>
      </div>
    </div>
    {% endblock %}
  </div>
  {% endblock %}
</div>

{% block script %}
<script>
  function openNav() {
    document.getElementById("sidebar").classList.remove("hidden");
    document.getElementById("sidebar-button").onclick = closeNav;
  }

  function closeNav() {
    document.getElementById("sidebar").classList.add("hidden");
    document.getElementById("sidebar-button").onclick = openNav;
  }

  var modal = document.getElementById("pn-Modal");
  var span = document.getElementById("pn-closeModal");

  span.onclick = function() {
    modal.style.display = "none";
  }

  window.onclick = function(event) {
    if (event.target == modal) {
      modal.style.display = "none";
    }
  }
</script>
{% endblock %}

{% block state_roots %}
{{ super() }}
{% endblock %}

{% endblock %}
