{% set color = app.session.get('color') %}

{% set logo = app.session.get('logo') %}
{% set fgheader = app.session.get('fgheader') %}
{% set header =  app.session.get('header') %}
{% set heightheader =  app.session.get('heightheader') %}
{% set colorR = color['mainrgb']['r'] %}
{% set colorG = color['mainrgb']['g'] %}
{% set colorB = color['mainrgb']['b'] %}

{% set theme = app.session.get('theme') %}
{% if theme is not empty %}
    {{ include('@Theme/'~theme~'/function.html.twig') }}
    {% import '@Theme/constant.html.twig' as constant %}

    {% set logo = constant.logo().__toString %}
    {% set header = constant.header().__toString %}
    {% set heightheader = constant.heightheader().__toString %}
    {% set colorR = constant.colorR.__toString %}
    {% set colorG = constant.colorG.__toString %}
    {% set colorB = constant.colorB.__toString %}
{%endif%}

<!DOCTYPE html>
<html>   
    {{ include('@CadolesCore/Include/head.html.twig') }}

    <style>

    {% block localstyle %}

    {% endblock %}
    
    </style>

    {% if maxwidth is defined and maxwidth %}
        {% set bodystyle="simple" %}
    {% elseif useheader %}
        {% set bodystyle="body" %}
    {% else %}
        {% set bodystyle="simple" %}
    {% endif %}

    {% if app.user %}
        {% for usergroup in app.user.groups %}
            {% set bodystyle = bodystyle~" grp-"~usergroup.group.label|replace({" ":"", "'":""}) %}
        {% endfor %}
    {% endif %}

    <body class="{{ bodystyle }}">
        <div id="wrapper">
            {% if useheader and app.request.attributes.get('_route')=='cadoles_core_home' %}
                {{ render(url("cadoles_core_checkuser")) }}
            {% endif %}
            
            {% if fgheader==1 %}     
                {% if useheader %}
                    <div class="header" style="height:{{ heightheader }}px; background-image: linear-gradient(90deg,rgba({{ colorR }},{{ colorG }},{{ colorB }},1),rgba({{ colorR }},{{ colorG }},{{ colorB }},0.1)),url(/{{ alias }}/{{ header }});">
                        <a class="title" style="cursor: pointer" href="{{ path("cadoles_core_home") }}">
                            <img id="logo" src="/{{ alias }}/{{ logo }}" style="height:{{ heightheader-40 }}px;">
                            {% if not app.session.get('sublogo') is empty %}
                                <img id="logo" src="/{{ alias }}/{{ app.session.get('sublogo') }}" style="height:{{ heightheader-40 }}px;">
                            {% endif %}
                            <span style="height:{{ (heightheader-20) }}px; line-height:{{ (heightheader-20) }}px;">
                                <div>{{ app.session.get('appname') }}</div>
                                {% if not app.session.get('subappname') is empty %}
                                    <small>{{ app.session.get('subappname') }}</small>
                                {% endif %}
                            </span>

                        </a>

                        <div class="navbar-header">
                            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                                <span class="sr-only">Toggle navigation</span>
                                <span class="icon-bar"></span>
                                <span class="icon-bar"></span>
                                <span class="icon-bar"></span>
                            </button>
                        </div>

                        <ul class="nav navbar-top-links navbar-right">
                            {% if mustread is not defined %}
                                {{ include('@CadolesCore/Include/menu.html.twig') }}
                            {% endif %}
                        </ul>

                        {% if app.user %}
                        <div id="navbar-nameuser"><a href="{{ path('cadoles_core_user') }}" title="Profil">{{ app.user.firstname }} {{ app.user.lastname }}</a></div>
                        {% endif %}
                    </div>
                {% endif %}
            {% endif %}

            <!-- Navigation -->
            {% if useheader %}
                <nav class="navbarsmall navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0;{% if fgheader==1 %} display:none; {% endif %}">
                    <div class="navbar-header">
                        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                            <span class="sr-only">Toggle navigation</span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                        </button>

                        <a class="navbar-brand" href="{{ path("cadoles_core_home") }}">
                        <img id="logo" src="/{{ alias }}/{{ logo }}">
                        <span id="navbarsmalltitle">{{ app.session.get('appname') }}</span>
                        </a>
                    </div>
    
                    <ul class="nav navbar-top-links navbar-right">
                        {% if app.user %}
                            <a id="navbar-nameuser" href="{{ path('cadoles_core_user') }}" title="Profil">{{ app.user.firstname }} {{ app.user.lastname }}</a>
                        {% endif %}
                        {% if mustread is not  defined  %}
                            {{ include('@CadolesCore/Include/menu.html.twig') }}
                        {% endif %}
                    </ul>
                </nav>
            {% endif %}

            {% if usemenu %}
                <nav id="appmenu" class="navbarheader navbar navbar-default navbar-static-top navbar-collapse" role="navigation" style="margin-bottom: 0">
                    {% block appmenu %}

                    {% endblock %}
                </nav>    
            {% endif %}    

            {% if usesidebar %}
                <nav>
                    <div class="navbar-default sidebar" role="navigation">
                        <div class="sidebar-nav navbar-collapse">
                            <ul class="nav in" id="side-menu">
                                {% block sidebar %}
                                    {{ include('@CadolesCore/Include/sidebar.html.twig') }}
                                {% endblock %}
                            </ul>
                        </div>
                    </div>                   
                </nav>
            {% endif %} 




            <div id="page-wrapper" class="{% if maxwidth is defined and maxwidth %} page-maxed {% endif %}" style="min-height:1200px; {% if not usesidebar %}  margin:0px; {% endif %}{% if not useheader %}  background-color:transparent; {% endif %} ">
                <div class="container-fluid">
                    <div class="row">
                    {% block pagewrapper %}

                    {% endblock %}
            
            
                    </div>
                </div>
            </div>
        </div>
               
        {{ include('@CadolesCore/Include/footer.html.twig') }}

        {% block localexternalscript %}

        {% endblock %}

        <script>
            {% block localjavascript %}

            {% endblock %}
        </script>

        {% if activate_widsonde and not framed is defined %}
            {{ render(path("cadoles_core_sonde")) }}
        {% endif %}

    </body>
</html>
