{% 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-link" data-id="{{ entity.id }}" loc="{{ entity.loc }}">
        <div class="widgetheader">
            {% if target == 'frame' %}
                <a style="cursor:pointer; {{ stylelink }}" onClick="showFrameitem('link{{ entity.id }}','{{ url|replace({'#login#': username}) }}')">
            {% elseif target == "_self" %}
                <a style="{{ stylelink }}"href="{{ url|replace({'#login#': username}) }}" target="{% if access=="user" %}_top{% else %}{{ target }}{% endif %}">
            {% else %}
                <a style="{{ stylelink }}" href="{{ url|replace({'#login#': username}) }}" target="{{ target }}">
            {% endif %}   
            {% 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-link" 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 %}
        </div>


        <div class="widgetheader" style="{{ stylewidgetbodyimage }}; height:100%;">
            {% if target == 'frame' %}
                <a style="cursor:pointer; {{ stylelink }}" onClick="showFrameitem('link{{ entity.id }}','{{ url|replace({'#login#': username}) }}')">
            {% elseif target == "_self" %}
                <a style="{{ stylelink }}"href="{{ url|replace({'#login#': username}) }}" target="{% if access=="user" %}_top{% else %}{{ target }}{% endif %}">
            {% else %}
                <a style="{{ stylelink }}" href="{{ url|replace({'#login#': username}) }}" target="{{ target }}">
            {% endif %}   
            {% if entity.icon %}
                <img src="{{ asset(entity.icon.label) }}" style="max-height: 100%; width: auto; display: block; margin: auto; padding-top: 10px;" />
            {% else %}
                <img src="{{ asset("uploads/icon/icon_pin.png") }}" style="max-height: 100%; width: auto; display: block; margin: auto; padding-top: 10px;" />
            {% endif %}

            
            <div style="text-align: center;">{{ entity.name }}</div>
            </a>
        </div>
    </div>
{% endif %}


