{% 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) %}

{% if modedesktop==0 %}
    {% set stylegrid="" %}
{% elseif modedesktop==1 %}
    {% set stylegrid="grid-medium" %}
{% elseif modedesktop==2 %}
    {% set stylegrid="grid-small" %}
{% elseif modedesktop==3 %}
    {% set stylegrid="grid-list" %}    
{% endif %}

{% set colorbodyfont = "" %}
{% if entity.colorbodyfont is not null %}
    {% set colorbodyfont = "color: #" ~ entity.colorbodyfont %}
{% endif %}


{%if mini %}
    <div class="widget widget-mini widget-appexternal" 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-appexternal" 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 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 }}">
            {% for itemcategory in itemcategorys %}
                {% set haveitem=false %}

                {% for item in items | filter(item => item.itemcategory == itemcategory) %}

                    {% if loop.index ==1 %}
                    {% set haveitem=true %}

                    {% if itemcategorys|length > 1 %}
                    <h3 class="grid-title" style="{{ colorbodyfont }}" data-idcategory="{{ itemcategory.id }}">{{ itemcategory.label }}</h3>
                    {% endif %}

                    <div class="grid clearfix">
                        <div class="grid-sizer {{ stylegrid }}"></div>
                        <div class="grid-gutter-sizer"></div>
                    {% endif %}
                                    
                        <div class="grid-item {{ stylegrid }}" data-idcategory="{{ item.itemcategory.id }}" data-iditem="{{ item.id }}">
                            <div class="grid-item-content" style="background-color: {{ item.color ? "#"~item.color : '#'~colormain }};">
                                <a href="{{ item.url }}" target="_blank">


                                <div class="item-link clearfix">
                                    <div class="grid-item-logo">
                                        <img class="grid-item-img" height="110" src="{{ asset("uploads/icon/"~item.icon) }}">
                                    </div>

                                    <div class="grid-item-title">
                                        <h2>{{ item.title }}</h2>
                                        <span>{{ item.subtitle|nl2br }}</<span>
                                    </div>                    
                                </div>
                                </a>
                            </div>
                        </div>
                {% endfor %}
                {% if haveitem %}            
                    </div>
                {% endif %}
            {% endfor %}
        </div>
    </div>
{% endif %}



