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

{%if mini %}
    <div class="widget widget-mini widget-blog" 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-blog" 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 access=="config" %}
            <a title="Gérer mes Blogs" href='{{ path('cadoles_portal_config_blog') }}' style="{{ stylewidgetmenu }}"><i class="fa fa-th fa-fw"></i></a>
            {% else %}
                {% if canadd %}
                    {% set idblog = "" %}
                    {% set url=  path('cadoles_portal_user_blogarticle_submit') %}
                    {% if usage=="group" and firstblog is defined %}
                        {% set url= path('cadoles_portal_user_blogarticle_submit',{idblog:firstblog,page:entity.page.id}) %}
                    {% endif %}

                    <a title="Créer un Article" onClick="showFrameitem('blog','{{ url }}',true)" style="{{ stylewidgetmenu }}"><i class="fa fa-plus fa-fw"></i></a>
                {% endif %}

                {% set url= path('cadoles_portal_user_blog_view') %}
                {% if usage=="group" and firstblog is defined %}
                    {% set url= path('cadoles_portal_user_blog_view',{id:firstblog}) %}
                {% endif %}

                <a title="Voir mes Blogs" onClick="showFrameitem('blog','{{ url }}',true)" style="{{ stylewidgetmenu }}"><i class="fa fa-th 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 blogarticles|length >= 1 %}
            <div class="widgetbody" style="{{ stylewidgetbody }}">
                <div class="grid clearfix">
                    {% for blogarticle in blogarticles %}
                        {% if loop.index==1 %}
                            <div class="grid-sizer grid-preview"></div>
                            <div class="grid-gutter-sizer grid-preview-gutter-sizer"></div>
                        {% endif %}

                        <div class="grid-item grid-preview" style="{{ stylewidgetbodyreverse }};">
                            <div class="grid-item-content">
                                <a href onClick="showFrameitem('blog','{{ path('cadoles_portal_'~access~'_blogarticle_view',{'id':blogarticle.id}) }}',true)">
                                    {% if blogarticle.image is not empty %}
                                    <div class="grid-item-logo">
                                        <img class="grid-item-vignette" src="/{{alias}}/{{blogarticle.image|replace({"/blogarticle/":"/blogarticle/thumb-"})}}" width="100%">
                                    </div>                                

                                    {% endif %}
                                    <div class="caption" style="{{ stylewidgetbodyreverse }};">
                                        <div class="grid-item-title" style="{{ stylewidgetbodyreverse }};">
                                            <h2>{{blogarticle.name }}</h2>
                                            <small>publié par {{ blogarticle.user.username }} le {{ blogarticle.submit|date("d/m/Y à H:i") }}<br>dans le blog {{blogarticle.blog.name }}</small>
                                        </div>
                                    </div>
                                </a>
                            </div>
                        </div>
                    {% endfor %}
                </div>
            </div>
        {% endif %}
    </div>
{% endif %}  


