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

<style>



</style>

{%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="{{ 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-project" 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 href='{{ path('app_portal_config_project') }}' style="{{ stylewidgetmenu }}"><i class="fa fa-plus fa-fw"></i></a>
            {% elseif app.user %}
            {% set idproject = "" %}
            {% set urladd=  path('app_portal_user_projecttask_submit') %}
            {% set urlview=  path('app_portal_user_project_view') %}
            {% if usage=="group" and firstproject is defined %}
                {% set urladd=  path('app_portal_user_projecttask_submit',{idproject:firstproject,page:entity.page.id}) %}
                {% set urlview=  path('app_portal_user_project_view',{id:firstproject}) %}
            {% endif %}
            <a onClick="showFrameitem('project','{{ urladd }}',true)" style="{{ stylewidgetmenu }}" title="Ajouter une Tâche"><i class="fa fa-plus fa-fw"></i></a>
            <a onClick="showFrameitem('project','{{ urlview }}',true)" style="{{ stylewidgetmenu }}" title="Gérer mes Tâches"><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="{{ 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 projecttasks|length >= 1 %}
            <div class="widgetbody" style="{{ stylewidgetbody }}">
                <div class="grid clearfix">
                    {% for projecttask in projecttasks %}
                        {% if loop.index==1 %}
                            <div class="grid-sizer grid-list"></div>
                            <div class="grid-gutter-sizer"></div>
                        {% endif %}

                        <div class="grid-item grid-list">
                            {% set colortask = color['main'] %}
                            {% if projecttask.projecttasktag %}
                                {% set colortask = projecttask.projecttasktag.color %}
                            {% endif %}
                            <div class="grid-item-content" style="background-color:#{{ colortask }}; {%if not entity.border%}padding:5px;{%endif%}">
                                <a title="Voir la Tâche" href="{{ path('app_portal_'~access~'_projecttask_view',{'id':projecttask.id,page:entity.page.id})  }}">

                                    <div class="item-link clearfix">
                                        <div class="grid-item-logo" style="width:10%; margin:0px; text-align: center;">
                                            {% if projecttask.user is empty %}
                                                <img class='grid-item-img avatar' src="{{ asset("uploads/avatar/"~projecttask.owner.avatar) }}" style="width:55px; height:auto">
                                            {% else %}
                                                <img class='grid-item-img avatar' src="{{ asset("uploads/avatar/"~projecttask.user.avatar) }}" style="width:55px; height:auto">
                                            {% endif %}
                                        </div>
                                        <div class="grid-item-title" style="width:90%; position:initial; display: inline-block; padding:0px">
                                            <h2 style="line-height:18px;height:auto;padding-left:5px;">{{projecttask.name}}</h2>

                                            <div style="font-size:9px; display:inline-block; width:40%;padding-left:5px;">Affectée à
                                                {% if projecttask.user is empty %}
                                                    {{ projecttask.owner.username }}
                                                {% else %}
                                                    {{ projecttask.user.username }}
                                                {% endif %}
                                                <br>Crée le {{ projecttask.submit|date("d/m/Y à H:i") }}
                                                <br>Dans le projet {{projecttask.project.name }}
                                            </div>

                                            <div style="text-align: right; font-size:9px; display:inline-block; width:35%;">
                                                Priorité = {{ projecttask.priority }}</br>
                                                Avant le = {{ projecttask.end|date("d/m/Y") }}</br>
                                                {% if projecttask.projecttasktag %}
                                                    Type = {{ projecttask.projecttasktag.name }}<br>
                                                {% endif %}
                                                {% if projecttask.projecttaskstatus %}
                                                    Statut = {{ projecttask.projecttaskstatus.name }}<br>
                                                {% endif %}
                                            </div>
                                            <div style="margin-top:-5px; text-align: right; display:inline-block; width:20%;">
                                                <div style="font-size:35px; line-height:30px">
                                                    {{ projecttask.percentage }}<i style="font-size:12px">%</i>
                                                </div>
                                            </div>

                                        </div>

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



