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

{% import "Pagewidget/constants.twig" as constants %}

{% set colormain = constants.mycolormain() %}
{% set stylewidget = constants.mystylewidget(entity) %}
{% set stylewidgetmenu = constants.mystylewidgetmenu(entity) %}
{% set stylewidgetheader = constants.mystylewidgetheader(entity) %}
{% set stylewidgetbody = constants.mystylewidgetbody(entity) %}
{% set stylewidgetbodyreverse = constants.mystylewidgetbodyreverse(entity) %}

{% set permgroup = app.session.get('permgroup') %}
{% set canadd = false %}
{% if is_granted('ROLE_ADMIN') or (is_granted('ROLE_MODO') and (permgroup=="ROLE_MODO" or permgroup=="ROLE_ANIM" or permgroup=="ROLE_USER")) or (is_granted('ROLE_ANIM') and (permgroup=="ROLE_ANIM" or permgroup=="ROLE_USER")) or (is_granted('ROLE_USER') and permgroup=="ROLE_USER") %}
    {% set canadd = true %}
{% endif %}

{% if mini %}
    <div class="widget widget-mini widget-group" data-id="{{ entity.id }}" loc="{{ entity.loc }}">
        <div class="widgetheader">
            <a style="cursor:pointer" onClick="bigWidget({{entity.id}})">
            {% if entity.icon %}
                <img src="{{ asset(entity.icon.label) }}" class="logo" title="{{ entity.name }}"/>
            {% else %}
                <img src="{{ asset("uploads/icon/icon_pin.png") }}" class="logo" title="{{ entity.name }}"/>
            {% endif %}
            </a>
        </div>
    </div>    
{% else %}
    <div class="widget {%if entity.border %} widget-bordered {%else%} widget-notbordered {%endif%} widget-group" data-id="{{ entity.id }}" loc="{{ entity.loc }}" style="{{ stylewidget }}" height="{{ entity.height }}px">
        <div class="widgetmenu">
            {% if canupdate %}
                <i class="fa fa-trash fa-fw" title="Supprimer le Widget" onClick="delWidget({{ entity.id }})" style="{{ stylewidgetmenu }}"></i>
                <i class="fa fa-file fa-fw" title="Modifier le Widget" onClick="modWidget({{ entity.id }})" style="{{ stylewidgetmenu }}"></i>
            {% endif %}

            {% if canadd %}
                <a title="Ajouter un Groupe" href="{{ path('app_core_user_group_submit') }}" target="_top">
                <i class="fa fa-plus fa-fw" style="{{ stylewidgetmenu }}"></i>
                </a>
            {% endif %}       

            {% if look=="list" %}
            <i class="glyphicon glyphicon-resize-small" title="Réduire le Widget" onClick="smallWidget({{ entity.id }})" style="{{ stylewidgetmenu }}"></i>
            {% else %}
            <i class="glyphicon glyphicon-resize-full" title="Agrandir le Widget" onClick="bigWidget({{ entity.id }})" style="{{ stylewidgetmenu }}"></i>
            {% endif %}    
        </div>

        <div class="widgetheader" style="{{ stylewidgetheader }}">
            {% if entity.icon %}
                <img src="{{ asset(entity.icon.label) }}" class="logo"/>
            {% else %}
                <img src="{{ asset("uploads/icon/icon_pin.png") }}" class="logo"/>
            {% endif %}
            <span class="title">{{ entity.name }}</span>


        </div>

        <div class="widgetbody" style="{{ stylewidgetbody }}; overflow-x:hidden; ">
            <div class="grid clearfix">
                <div class="grid-sizer  grid-small"></div>
                <div class="grid-gutter-sizer"></div>         
                {% for group in groups %}
                    <div class="grid-item grid-small" >
                        <div class="grid-item-content" style="background-color:{{ group.color ? "#"~group.color : '#'~colormain }}">      
                            <a href="{{path('app_core_home',{id:group.id})}}" target="_top" style="{{ stylewidgetbodyreverse }};">
                                <div class="item-link clearfix">
                                    <div class="grid-item-logo">
                                        {% if group.icon %}
                                            <img class="grid-item-img" height="110" src="{{ asset(group.icon) }}" />
                                        {% else %}
                                            <img class="grid-item-img" height="110" src="{{ asset("uploads/icon/icon_users.png") }}" />
                                        {% endif %}  
                                    </div>                    
            
                                
                                    <div class="grid-item-title">
                                        <h2>{{ group.title }}</h2>
                                    </div>
                                </div>
                            </a>
                        </div>
                    </div>            
                {% endfor %}

                {% if canadd %}
                    <div class="grid-item grid-small">
                        <div class="grid-item-content" style="{{ stylewidgetbodyreverse }};">  
                            <a title="Ajouter un Groupe" href="{{path('app_core_user_group_submit')}}" target="_top" style="{{ stylewidgetbodyreverse }};">
                                <div class="item-link clearfix">
                                    
                                    <div class="grid-item-logo">
                                        <img class="grid-item-img imageshadow" height="110" src="{{ asset("uploads/icon/icon_add.png") }}" />
                                    </div>                    
            
                                
                                    <div class="grid-item-title">
                                        <h2>Ajouter un Groupe</h2>
                                    </div>
                                </div>
                            </a>
                        </div>
                    </div>  
                {% endif %}
            </div>
        </div>
    </div>
{% endif %}


