{% 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 stylewidget = constants.mystylewidget(entity) %}
{% set stylewidgetmenu = constants.mystylewidgetmenu(entity) %}
{% set stylewidgetheader = constants.mystylewidgetheader(entity) %}
{% set stylewidgetbody = constants.mystylewidgetbody(entity) %}
{% set stylewidgetbodyimage = constants.mystylewidgetbodyimage(entity) %}

{% set color = app.session.get('color') %}
{% set stylelink = "color:#" ~ entity.colorheaderfont ~ ";" %}
{% if entity.colorheaderfont is null %}
    {% set stylelink = "color:#" ~ color['fontcolorhover'] ~ ";" %}
{% endif %}

{% if app.user %}
    {% set username = app.user.username %}
{% else %}
    {% set username = "" %}
{% endif %}

{%if mini %}
    <div class="widget widget-mini widget-slide" 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-slide" 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 %}
                <i title="Gérer le Carrousel" class="fa fa-th fa-fw" onClick="listSlide({{ 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="{{ stylewidgetbodyimage }}">
            {% set intervalmilli = interval * 1000 %}
            <div class="slick" data-slick='{"autoplaySpeed": {{ intervalmilli }} }'>
                {% for slide in slides %}
                    <div style="background-image:url({{ asset(slide.image) }}); ">
                    
                        {% if slide.title is not empty %}
                            <h1 class="slicktitle" style="{{ stylelink }}">{{slide.title}}</h1>
                        {% endif %}

                        {% if slide.url is not empty %}
                            {% if slide.target == 'frame' %}
                                <a class="slicklink" style="{{ stylelink }} cursor:pointer" onClick="showFrameitem('slide{{ slide.id }}','{{ slide.url|replace({'#login#': username}) }}')">
                            {% elseif slide.target == "_self" %}
                                <a class="slicklink" style="{{ stylelink }}" href="{{ slide.url|replace({'#login#': username}) }}" target="{% if access=="user" %}_top{% else %}{{ slide.target }}{% endif %}">
                            {% else %}
                                <a class="slicklink" style="{{ stylelink }}" href="{{ slide.url|replace({'#login#': username}) }}" target="{{ slide.target }}">
                            {% endif %}

                            <i class="fa fa-link"></i></a>
                        {% endif %}

                        {% if slide.subtitle is not empty %}
                            <span class="slicksubtitle" style="{{ stylelink }}">{{slide.subtitle}}</span>
                        {% endif %}                    



                    </div>

                {% endfor %}
            </div>
        </div>
    </div>
{% endif %}




