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

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

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

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

{% if modelist==0 %}
    {% set stylegrid="grid-preview" %}
{% elseif modelist==1 %}
    {% set stylegrid="grid-list" %}
{% endif %}

{%if mini %}
    <div class="widget widget-mini widget-groupmessage" 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-groupmessage" 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="/{{ 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 messages is not empty %}
        <div class="widgetbody" style="{{ stylewidgetbody }} ">
            <div class="grid clearfix">
                <div class="grid-sizer {{stylegrid}}"></div>
                <div class="grid-gutter-sizer {{stylegrid}}-gutter-sizer"></div>
                {% set nbaff=0 %}
                {% for message in messages %}
                    {% set nbaff=nbaff+1 %}
                    {% set class="" %}
                    {% set style="" %}
                    {% if nbaff > nbarticle %}
                        {% set class="msg-hidden" %}
                        {% set style="display:none" %}
                    {% endif %}

                    <div class="grid-item {{ stylegrid }} msg-{{ message.id }} {{class}}" style="{{ stylewidgetbodyreverse }}; {{style}};">
                        <div class="grid-item-content" style="background-color:{{ message.color ? "#"~message.color : '#'~colormain }}">
                            <div class="item-link clearfix">
                                <div class="grid-item-logo">
                                    <img style='cursor:pointer' onClick="seeUser({{message.user.id}})" class="grid-item-img avatar" src="/{{alias}}/uploads/avatar/{{message.user.avatar}}" width="100%">
                                    <a onClick="hideMessage({{message.id}})" style="cursor:pointer;" title="Ne plus afficher"><i class="fa fa-eye-slash"></i></a>
                                </div>

                                <div class="caption">
                                    <div class="grid-item-title" style="position:inherit; width:85%">
                                        {{message.user.lastname}} {{message.user.firstname}}<br>
                                        <small>{{message.date|date('d/m/Y H:i')}} dans le groupe <u><a href="{{path('cadoles_core_home',{id:message.pageid})}}" target="_top">{{ message.pagetitle }}</a></u></small><br><br>                            
                                        {{ message.topic | raw }}                                                   
                                    </div>   
                                </div>
                            </div>
                        </div>
                    </div>
                {% endfor %}
            </div>
        </div>
        {% endif %}
    </div>
{% endif %}


