{% extends 'base.html.twig' %}

{% block pagewrapper %}
{{ form_start(form) }}
    <h1 class="page-title">
    {% if mode=="update" or mode=="updatetemplate" %}
    Modification Widget
    {% elseif mode=="submit" or mode=="submittemplate"  %}
    Création Widget
    {% endif %}
    </h1>

    <p>
    {{ form_widget(form.submit) }}
    
    {% if access=="config" %}
        {% if mode=="update" %}
            <a class="btn btn-secondary" href="{{ path('app_portal_config_page_view',{id:idpage}) }}">Annuler</a>
        {% else %}
            <a class="btn btn-secondary" href="{{ path('app_portal_config_pagetemplate_view',{id:idpage}) }}">Annuler</a>
        {% endif %}    
    {% else %}
        {% if mode=="update" %}
            <a class="btn btn-secondary" href="{{ path('app_portal_user_page_view',{id:idpage,usage:usage,group:group}) }}">Annuler</a>
        {% else %}
            <a class="btn btn-secondary" href="{{ path('app_core_home',{id:idpage}) }}">Annuler</a>
        {% endif %}    
    {% endif %}


    </p>

    {% if app.session.flashbag.has('error') %}
        <div class='alert alert-danger' style='margin: 5px 0px'>
            <strong>Erreur</strong><br>
            {% for flashMessage in app.session.flashbag.get('error') %}
                {{ flashMessage }}<br>
            {% endfor %}
        </div>
    {% endif %}

    {% if app.session.flashbag.has('notice') %}
        <div class='alert alert-info' style='margin: 5px 0px'>
            <strong>Information</strong><br>
            {% for flashMessage in app.session.flashbag.get('notice') %}
                {{ flashMessage }}<br>
            {% endfor %}
        </div>
    {% endif %}
    
    <div class="row">           
        <div class="col-md-8">  
            <div class="card">
                <div class="card-header"><i class="fa fa-pencil-alt fa-fw"></i> Informations</div>
                <div id="col1" class="card-body">
                    {{ form_row(form.name) }}
                </div>
            </div>
        </div>

        <div class="col-md-4">  
            <div class="card">
                <div class="card-header"><i class="fa fa-pencil-alt fa-fw"></i> Image</div>
                <div class="card-body">        
                    <div id="diviconsel" class="col-md-12 text-left" style="height:140px; padding:20px; text-align:center; background-color: #{{ color["main"] }};">
                        {% if entity.icon %}
                        <img src="{{ asset(entity.icon.label) }}" height="100" />
                        {% endif %}
                    </div>
                    <div class="col-md-12" style="text-align:center;padding:0px">
                        {{ form_row(form.idicon) }}
                        <a class="btn btn-success" onClick="selectIcon()" title='Ajouter' style="width:100%">Selectionner une Icône</a>
                    </div>  
                </div>
            </div>
        </div>
    </div>

    <div class="card">
        <div class="card-header"><i class="fa fa-pencil-alt fa-fw"></i> Détails</div>
        <div class="card-body">
            <div class="row">
                <div id="col2" class="col-md-4">  
                    {{ form_row(form.height) }}
                    {{ form_row(form.autoajust) }}
                    {{ form_row(form.border) }}
                    {{ form_row(form.opened) }}
                </div>  

                <div id="col3" class="col-md-4">  
                    {{ form_row(form.colorheaderback) }}
                    {{ form_row(form.colorheaderfont) }}
                    {{ form_row(form.colorbodyback) }}
                    {{ form_row(form.colorbodyfont) }}
                </div>  

                <div id="col4" class="col-xs-4">  

                </div>  

                <div id="col5" class="col-md-12" style="clear:both">  
                    {{ form_widget(form) }}
                </div>  
            </div>
        </div>
    </div>

{{ form_end(form) }}
{% endblock %}

{% block localjavascript %}

    $(document).ready(function() {
        $(".control-label").each(function( element ) {
            var loc = $(this).attr('loc');
            if (typeof loc !== typeof undefined && loc !== false) {
                $(this).parent().appendTo("#"+loc);
            }
        });

        $("#col2").children(".form-group").each(function( element ) {
            $(this).css("zoom","80%");
        });

        $("#col3").children(".form-group").each(function( element ) {
            $(this).css("zoom","80%");
        });        

        $("#col4").children(".form-group").each(function( element ) {
            $(this).css("zoom","80%");
        });        
    });

    function selIcon(idicon,label) {
        $("#pagewidget_idicon").val(idicon);
        $("#diviconsel img").remove();

        url="{{ asset("xxx")}}";
        url=url.replace("xxx",label);
        $("#diviconsel").append("<img src='"+url+"'>");
        $("#diviconsel img").attr("height","100px");
        $("#mymodal").modal("hide");
    }

    function selectIcon() {
        $("#mymodal").find(".modal-title").html("SELECTIONNER UNE ICONE");
        var url="{{ path('app_portal_user_icon_select') }}";
        $("#mymodal").find("#framemodal").attr("src",url);
        $("#mymodal").modal("show");
    }


{% endblock %}