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

{% if modedesktop==0 %}
    {% set stylegrid="" %}
{% elseif modedesktop==1 %}
    {% set stylegrid="grid-medium" %}
{% elseif modedesktop==2 %}
    {% set stylegrid="grid-small" %}
{% elseif modedesktop==3 %}
    {% set stylegrid="grid-list" %}    
{% endif %}

{% set colorbodyfont = "" %}
{% if entity.colorbodyfont is not null %}
    {% set colorbodyfont = "color: #" ~ entity.colorbodyfont %}
{% endif %}

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

{%if mini %}
    <div class="widget widget-mini widget-bookmark" 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-bookmark" 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 class="fa fa-plus fa-fw" title="Ajouter un Favori" onClick="addBookmark({{ entity.id }},false)" 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="{{ asset(entity.icon.label) }}" class="logo"/>
            {% else %}
                <img src="{{ asset("uploads/icon/icon_pin.png") }}" class="logo"/>
            {% endif %}
            <span class="title">{{ entity.name }}</span>
        </div>

        {% if bookmarks is not empty or canadd %}
            <div class="widgetbody" style="{{ stylewidgetbody }}">
                <div class="bookmark-container">
                    <div class="grid clearfix">
                        <div class="grid-sizer {{ stylegrid }}"></div>
                        <div class="grid-gutter-sizer"></div>
                        {% for bookmark in bookmarks %}
                            <div class="grid-item {{ stylegrid }}">
                                <div class="grid-item-content" style="background-color: {{ bookmark.color ? "#"~bookmark.color : "#"~color['main'] }};">
                                    {% if canadd %}
                                        <a  style="cursor:pointer" onClick="modBookmark({{ bookmark.id }})" class="item-update"><i style="color: #FFF" class="fa fa-file" title="Modifier le favori"></i></a>
                                    {% endif %}
                                    
                                    {% if bookmark.target == 'frame' %}
                                        <a style="cursor:pointer" onClick="showFrameitem('bookmark{{ bookmark.id }}','{{ bookmark.url|replace({'#login#': username}) }}')">
                                    {% elseif bookmark.target == "_self" %}
                                        <a href="{{ bookmark.url|replace({'#login#': username}) }}" target="{% if access=="user" %}_top{% else %}{{ bookmark.target }}{% endif %}">
                                    {% else %}
                                        <a href="{{ bookmark.url|replace({'#login#': username}) }}" target="{{ bookmark.target }}">
                                    {% endif %}

                                    <div class="item-link clearfix">
                                        <div class="grid-item-logo" title="{{ bookmark.subtitle|nl2br }}">
                                            {% if bookmark.icon %}
                                                <img class="grid-item-img" height="110" src="{{ asset(bookmark.icon.label) }}">
                                            {% else %}
                                                <img class="grid-item-img" height="110" src="{{ asset("uploads/icon/icon_pin.png") }}">
                                            {% endif %}
                                        </div>

                                        <div class="grid-item-title">
                                            <h2>{{ bookmark.title }}</h2>
                                            <span>{{ bookmark.subtitle|nl2br }}</<span>
                                        </div>                    
                                    </div>
                                    </a>
                                </div>
                            </div>
                        {% endfor %}

                        {% if canadd %}
                        <div class="grid-item {{ stylegrid }}">
                            <div title="Ajouter un Favori" onClick="addBookmark({{ entity.id }},false)" class="grid-item-content" style="background-color: #{{color['main']}};cursor:pointer;">
                                <div class="item-link clearfix">
                                    <div class="grid-item-logo">
                                        <img class="grid-item-img imageshadow" height="110" src="{{ asset("uploads/icon/icon_add.png") }}">
                                    </div>
                                    <div class="grid-item-title">
                                        <h2>Ajouter</h2>
                                    </div>                              
                                </div>
                            </div>
                        </div>
                        {% endif %}
                    </div>
                </div>
            </div>
        {% endif %}
    </div>
{% endif %}    



