{% extends 'partials/base.html.twig' %}

{% macro pageLinkName(text) %}{{ text|lower|replace({' ':'_'}) }}{% endmacro %}

{% import _self as macro %}

{% set show_onpage_menu = header.onpage_menu == true or header.onpage_menu is null %}

{% block javascripts %}
    {% if show_onpage_menu %}
        {% do assets.add('theme://js/singlepagenav.min.js') %}
    {% endif %}
    {{ parent() }}
{% endblock %}

{% block bottom %}
    {{ parent() }}
{% endblock %}

{% block header_navigation %}
    {% if show_onpage_menu %}
        <ul class="navigation">
        {% for module in page.collection() if module.template == 'blog' %}
            {% set current_module = (module.active or module.activeChild) ? 'active' : '' %}
            <li><a class="{{ current_module }}" href="#{{ macro.pageLinkName(module.menu)|hyphenize }}">{{ module.menu }}</a></li>
        {% endfor %}
        {% for mitem in site.menu %}
            <li>
                <a {% if mitem.class %} class="{{ mitem.class }}" {% endif %} href="{{ mitem.url }}">
                    {% if mitem.icon %}<i class="fa fa-{{ mitem.icon }}"></i>{% endif %}
                    {{ mitem.text }}
                </a>
            </li>
        {% endfor %}
        </ul>
    {% else %}
        {{  parent() }}
    {% endif %}
{% endblock %}

{% block hero %}
    {% for module in page.collection() if module.template == 'modular/hero' %}
        <div id="{{ macro.pageLinkName(module.menu) }}"></div>
        {{ module.content|raw }}
    {% endfor %}
{% endblock %}

{% block body %}

  <section id="{{ macro.pageLinkName(page.menu) }}" class="section">
    <div class="content section-content">
      {{page.content}}
    </div>
  </section>

  {% for module in page.collection() if module.template == 'blog' %}

    <section id="{{ macro.pageLinkName(module.menu)|hyphenize }}" class="section">
      <div class="content section-content">
        <div class="block">
          <h2>{{ module.title }}</h2>
          <div class="arrow"></div>
            <div class="content">
              {{ module.content|raw }}
          </div>
        </div>
      </div>

      <div class="sous-section">

        {% for child in module.collection if child.template == 'items' %}
            {% include 'items.html.twig' %}
        {% endfor %}

        {% for child in module.collection if child.template == 'item-etapes' %}
            {% include 'item-etapes.html.twig' %}
        {% endfor %}

        {% for child in module.collection if child.template == 'blog' %}
          {% set gal = child.header.blog.config %}

          {% if gal %}

            {% include 'partials/sous-gal.html.twig' %}
          {% else %}
            {% include 'partials/no-gal.html.twig' %}
          {% endif %}

        {% endfor %}

      </div>

    </section>

  {% endfor %}

{% endblock %}
