{% 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 stylewidgetbodyframe = constants.mystylewidgetbodyframe(entity) %}
{% set stylewidgetbodyimage = constants.mystylewidgetbodyimage(entity) %}

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

{%if mini %}
    <div class="widget widget-mini widget-project" 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-url" 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>
        

        {% if imagemedia %}
            {% if entity.autoajust %}
                <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>
                <div class="widgetbody" style="{{ stylewidgetbodyframe }}">
                    <img src="{{ url|replace({'#login#': username}) }}" width="100%" >
                </div>
            {% else %}
                <div  class="widgetheader" style="{{ stylewidgetbodyimage }} width:100%; background-image: url({{ url|replace({'#login#': username}) }}); background-size:cover; background-position:center;")></div>
            {% endif %}
        {% else %}
            <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>

            <div class="widgetbody" style="{{ stylewidgetbodyframe }}">
                {% set minheight="" %}
                {%if look=="list" %}
                    {% set minheight="min-height:1300px;" %}
                {% endif %}
                <iframe src="{{ url|replace({'#login#': username}) }}" class="{% if entity.autoajust %}frameajust {% endif %}" style="{{ stylewidgetbodyframe }} {{minheight}}"></iframe>
            </div>
        {% endif %}
    </div>
{% endif %}
<script>

</script>

