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

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

{% 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 color = app.session.get('color') %}

{% set colorbodyback = entity.colorbodyback %}
{% if colorbodyback is null %}
    {% set colorbodyback = color['main'] %}
{% endif %}


{% set colorbodyfont = entity.colorbodyfont %}
{% if colorbodyfont is null %}
    {% set colorbodyfont = color['fontcolorhover'] %}
{% endif %}

{%if mini %}
    <div class="widget widget-mini widget-galery" data-id="{{ entity.id }}" loc="{{ entity.loc }}">
        <div class="widgetheader">
            <a style="cursor:pointer" onClick="bigWidget({{entity.id}})">
            {% if entity.icon %}
                <img src="/{{ alias }}/{{ entity.icon.label }}" class="logo" title="{{ entity.name }}"/>
            {% else %}
                <img src="/{{ alias }}/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-galery" 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 style="{{ stylewidgetmenu }}" data-toggle="modal" data-target="#mymodal" onClick="ModalLoad('mymodal','Fichiers','{{ path('cadoles_core_'~access~'_file_upload',{'id': 'widget-'~entity.id,'type':'image'}) }}');" title='Ajouter des Images'><i class="fa fa-plus fa-fw"></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="/{{ alias }}/{{ entity.icon.label }}" class="logo"/>
            {% else %}
                <img src="/{{ alias }}/uploads/icon/icon_pin.png" class="logo"/>
            {% endif %}
            <span class="title">{{ entity.name }}</span>
        </div>

        {% if files|length>0  or canadd %}
            <div class="widgetbody" style="{{ stylewidgetbody }}">
                <div class="grid clearfix">
                    {% if canadd %}
                        <div class="grid-sizer  grid-image"></div>
                        <div class="grid-gutter-sizer"></div>
                    {% endif %}   

                    {% for file in files|sort %}
                        {% if loop.index==1  and not canadd %}
                            <div class="grid-sizer grid-image"></div>
                            <div class="grid-gutter-sizer grid-gutter-sizer-image"></div>
                        {% endif %}
                    
                        <div class="grid-item grid-image">
                            <div class="grid-item-content">
                                {% if canadd %}
                                    <a  style="cursor:pointer" onClick="delFile('widget-{{ entity.id}}','{{file.name|e('js')|raw}}')" class="item-delete"><i style="color: #FFF" class="fa fa-trash" title="Supprimer le fichier"></i></a>
                                {% endif %}

                                <a style="cursor:pointer" onClick="showFrameitem('file-{{entity.id}}-{{loop.index}}','{{ path('cadoles_core_'~access~'_file_view',{'directory':'widget-'~entity.id,'filename':file.name,'navigation':true }) }}',true)">

                                <div class="item-link clearfix">
                                    <div class="grid-item-logo">
                                        <img class="grid-item-img" height="110" src="{{ file.thumb }}">
                                    </div>                 
                                </div>
                                </a>
                            </div>
                        </div>
                    {% endfor %}

                    {% if canadd %}
                        <div class="grid-item grid-list" style="{{ stylewidgetbodyreverse }};">
                            <div class="grid-item-content">
                                <a style="{{ stylewidgetmenu }}" data-toggle="modal" data-target="#mymodal" onClick="ModalLoad('mymodal','Fichiers','{{ path('cadoles_core_'~access~'_file_upload',{'id': 'widget-'~entity.id,'type':'image'}) }}');" title='Ajouter des Images'>
                                    <div class="item-link clearfix">
                                        <div class="grid-item-logo">
                                            <img class="grid-item-img imageshadow" height="110" src="/{{ alias }}/uploads/icon/icon_add.png" />
                                        </div>

                                        <div class="grid-item-title">
                                            <h2 style="{{ stylewidgetbodyreverse }}">Ajouter des Images</h2>
                                        </div>                    
                                    </div>
                                </a>
                            </div>
                        </div>
                    {% endif %}                
                </div>
            </div>
        {% endif %}
    </div>
{% endif %}    



