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

{% set logo = app.session.get('logo') %}
{% set fgheader = app.session.get('fgheader') %}
{% set fguserheader = app.session.get('fguserheader') %}
{% 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('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 %}


    {% if useheader and app.request.attributes.get('_route')=='app_core_home' %}
        {{ render(url("app_core_checkuser")) }}
    {% endif %}

    <body class="{{ bodystyle }}">
        <div class="d-flex flex-column ">
            {% if fgheader==1 and (fguserheader==1 or not app.user)%}     
                {% if useheader %}
                    <!-- Header -->
                    <div class="header sticky-top d-flex align-items-center" style="height:{{heightheader}}px; background-image: linear-gradient(90deg,rgba({{ colorR }},{{ colorG }},{{ colorB }},1),rgba({{ colorR }},{{ colorG }},{{ colorB }},0.1)),url({{ asset(header) }});">
                        <a href="{{ path('app_core_home')}}">
                            <img class="logo" src="{{ asset(logo) }}" style="height:{{heightheader-20}}px;margin-left:10px; max-height:120px;">
                            {% if not app.session.get('sublogo') is empty %}
                                <img class="logo" src="{{ asset(app.session.get('sublogo')) }}" style="height:{{ heightheader-20}}px;">
                            {% endif %}
                        </a>

                        <h1 class="flex-grow-1">
                            <a href="{{ path('app_core_home')}}">
                                {{app.session.get("appname")}}
                            </a>
                            <br>
                            <small><a href="{{ path('app_core_home')}}">{{app.session.get("subappname")}}</a></small>                        
                        </h1>

                        <div class="pe-3">
                            <nav class="nav">
                                {% if mustread is not defined %}
                                    {{ include('Include/menu.html.twig') }}
                                {% endif %}
                            </nav>

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

            
            {% if useheader %}
                <!-- Littleheader -->
                <div class="littleheader sticky-top align-items-center" style="{{ (fgheader==1 and (fguserheader==1 or not app.user)?'display:none;':'display:flex') }}">
                    <a href="{{ path('app_core_home')}}">
                        <img id="logo" src="{{ asset(logo) }}">
                        {% if not app.session.get('sublogo') is empty %}
                            <img id="logo" src="{{ asset(app.session.get('sublogo')) }}">
                        {% endif %}
                    </a>

                    <h1 class="flex-grow-1">
                        <a href="{{ path('app_core_home')}}">
                            {{app.session.get("appname")}}
                        </a>                     
                    </h1>

                    {% if mustread is not  defined  %}
                        <div class="ms-auto pe-3">
                            <nav class="nav">
                                {{ include('Include/menu.html.twig') }}
                                {% if usesidebar %}
                                    <a id="showsidebar" class="nav-link" title="Menu"><i class="fa fa-bars fa-fw"></i></a>
                                {% endif %}

                                {% if usemenu %}
                                    <a id="showmenu" class="nav-link" title="Menu"><i class="fa fa-bars fa-fw"></i></a>
                                {% endif %}                                
                            </nav>
                        </div>
                    {% endif %}
                </div>
            {% endif %}

            {% if usemenu %}
                <div id="menu">
                    {% block appmenu %}

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

            <main class="d-flex align-items-stretch">
                {% if usesidebar %}
                    {% block sidebar %}
                        {{ include('Include/sidebar.html.twig') }}
                    {% endblock %}
                {% endif %} 

                <div id="page-wrapper" class="flex-grow-1 {{ (useheader and not usesidebar)?"page-header" }} {{ (maxwidth is defined and maxwidth)?"page-maxed" }}" style="{{ (not useheader)? "background-color:transparent; " }}">
                    <div>
                        {% block pagewrapper %}

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

        {% block localexternalscript %}

        {% endblock %}

        <script>
            {% block localjavascript %}

            {% endblock %}
        </script>
    </body>
</html>
