{% set body_classes = body_class(['header-fixed', 'header-animated', 'header-dark', 'header-transparent', 'sticky-footer']) %}
{% set grid_size = theme_var('grid-size') %}
{% set compress = theme_var('production_mode') ? '.min.css' : '.css' %}
<!DOCTYPE html>
<html lang="{{ grav.language.getActive ?: grav.config.site.default_lang }}">
<head>
{% block head %}
    <meta charset="utf-8" />
    <title>{% if header.title %}{{ header.title|e('html') }} | {% endif %}{{ site.title|e('html') }}</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    {% include 'partials/metadata.html.twig' %}

    <link rel="icon" type="image/png" href="{{ url('theme://images/favicon.png') }}" />
    <link rel="canonical" href="{{ page.url(true, true) }}" />

    {% block stylesheets %}
      {% do assets.addCss('theme://css/jquery-ui.css') %}
      {% do assets.addCss('theme://css-compiled/template.css') %}
      {% do assets.addCss('theme://css/styles_3djs.css') %}
      {% do assets.addCss('theme://css/styles_paperjs.css') %}
      {# % do assets.addCss('theme://css/leaflet.css.css') % #}
      <link rel="stylesheet" href="user/themes/r2c/css/leaflet.css" crossorigin=""/>
    {% endblock %}

    {{ assets.css() }}

    <!-- dynamique js variables -->
    {# Pour déboguer les variables twig tu peux utiliser dump #}
    {# ça apparait dans la console de deboguage grav en bas de l'écran dans "messages" #}
    {# pour activer la console grav c'est dans /user/config/system.yalm debugger:enabled:true #}
    {% for module in page.collection %}
      {{ dump( module.slug )}}
      {% for submodule in module.collection %}
      {{ dump(submodule.header) }}
      {% endfor %}
    {% endfor %}

    {# le code pour de vrai :) #}
    {# définie les tableaux a remplir #}
    {% set mappoints = [] %}
    {% set links = [] %}
    {% set reseauxsociaux = [] %}
    {# boucle sur les modules puis les sous modules #}
    {# et en fonction du module remplit le bon tableau #}
    {% for module in page.collection %}
      {% for submodule in module.collection %}
        {% if module.slug == "_streetmap" %}
          {% set mappoints = mappoints|merge([submodule.header]) %}
        {% endif %}
        {% if module.slug == "_links" %}
          {% set links = links|merge([submodule.header]) %}
        {% endif %}
        {% if module.slug == "_reseaux-sociaux" %}
          {% set reseauxsociaux = reseauxsociaux|merge([submodule.header]) %}
        {% endif %}
      {% endfor %}
    {% endfor %}

    {# transforme les variable twig en variables js #}
    <script type="text/javascript">
      var dyn_data = {
        mappoints : {{ mappoints|json_encode() }},
        links : {{ links|json_encode() }},
        reseauxsociaux : {{ reseauxsociaux|json_encode() }}
      };
      console.log("dyn_data", dyn_data);
    </script>

    <!-- js assets -->
    {% block javascripts %}
        {% do assets.addJs('jquery', 101) %}
        {% do assets.addJs('theme://js/jquery-ui.js', {group:'bottom'}) %}
        {% do assets.addJs('theme://js/d3.js', {group:'bottom'}) %}
        {% do assets.addJs('theme://js/script_d3js.js', {group:'bottom'}) %}
        {% do assets.addJs('theme://js/paper_full.js', {group:'bottom'}) %}
        {% do assets.addJs('theme://js/jquery.ui.touch-punch.min.js', {group:'bottom'}) %}
        {% do assets.addJs('theme://js/script.js', {group:'bottom'}) %}

        {# % do assets.addJs('theme://js/leaflet.js', {group:'bottom'}) % #}
        {# do assets.addJs('theme://js/script_paperjs.js', {type:'text/paperscript', canvas:'canvas', group:'bottom'}) #}

        <script type="text/paperscript" src="user/themes/r2c/js/script_paperjs.js" canvas="canvas"></script>
        <script src="user/themes/r2c/js/leaflet.js" crossorigin=""></script>

    {% endblock %}

    {{ assets.js() }}

{% endblock head %}
</head>
<body id="top">

    <div id="page">
    {% block header %}
        <section id="header" class="section">
                <nav class="navbar">
                  <h1>
                    <a href="{{ home_url }}" class="navbar-brand mr-10">{{site.title}}</a>
                  </h1>

                    <section class="navbar-section">
                        <nav>
                          {% block header_navigation %}
                            {% include 'partials/navigation.html.twig' %}
                          {% endblock %}
                        </nav>
                        {% if config.plugins.login.enabled and grav.user.username %}
                            <span class="login-status-wrapper"><i class="fa fa-user"></i> {% include 'partials/login-status.html.twig' %}</span>
                        {% endif %}
                </nav>
            </section>
        </section>

    {% endblock %}

    {% block hero %}{% endblock %}


          <section id="start">
            <div id="handlers">

            <div class="handler hand1">
              <img src="user/themes/r2c/images/handler.svg" alt="">
            </div>

            <div class="handler hand2">
              <img src="user/themes/r2c/images/handler.svg" alt="">
            </div>
          </div>
        {% block body %}
            <section id="body-wrapper" class="section">
                <section class="container {{ grid_size }}">
                    {% block messages %}
                        {% include 'partials/messages.html.twig' ignore missing %}
                    {% endblock %}
                    {% block content %}{% endblock %}
                </section>
            </section>
        {% endblock %}
        </section>

    </div>

{% block footer %}
{% endblock %}

{% block bottom %}
    {{ assets.js('bottom') }}
{% endblock %}

</body>
