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

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

    <p>
        {{ form_widget(form.submit) }}
        {% if mode=="update" %}
        <a class="btn btn-secondary" href='{{ path('app_portal_'~access~'_blogarticle_view',{'id':entity.id}) }}'>Annuler</a>
        {% elseif mode=="submit" %}
            {% set blogid=0 %}
            {%if entity.blog.id is defined %}
                {% set blogid=entity.blog.id %}
            {%endif%}
        
            {% if pageid is empty %}
                <a class="btn btn-secondary" href='{{ path('app_portal_'~access~'_blog_view',{'id':blogid})}}'>Annuler</a>
            {% else %}
                <a class="btn btn-secondary" href="{{path('app_core_home',{id:pageid})}}" target="_top">Annuler</a>
            {% endif %}
        {% endif %}

        {% if mode=="update" %}
        <a href={{ path('app_portal_'~access~'_blogarticle_delete',{'id':entity.id}) }}
            class="btn btn-danger float-end"
            data-method="delete" data-csrf="_token:{{ 'csrf' }}"
            data-confirm="Êtes-vous sûr de vouloir supprimer cet article ?">
            Supprimer
        </a>
        {% 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="form-group row clearfix">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">
                    <i class="fa fa-pencil-alt fa-fw"></i> Informations
                </div>

                <div class="card-body">        
                    {{ form_row(form.name) }}
                    {{ form_row(form.blog) }}
                    {{ form_row(form.fgcomment) }}
                </div>
            </div>
        </div>
        
        <div class="col-md-4">
            <div class="card">
                <div class="card-header">
                    <i class="fa fa-pencil-alt fa-fw"></i> Détails
                </div>

                <div class="card-body">              
                    <a class="btn btn-info" style="width:100%" data-bs-toggle="modal" data-bs-target="#mymodal" onClick="ModalLoad('mymodal','Image à la une','{{ path('app_portal_'~access~'_blogarticle_image') }}');" title='Ajouter un Header'>Téléchargez une image à la une</a>
                    <img id="blogarticle_image_img" src="{{ (entity.image?asset(entity.image)) }}" style="width:100%;margin:auto;display:block;">
                    {{ form_widget(form.image) }}
                </div>
            </div>     
        </div>

        <div class="col-md-12">
            <div class="card">
                <div class="card-header">
                    <i class="fa fa-pencil-alt fa-fw"></i> Editeur
                </div>

                <div class="card-body">           
                    {{ form_widget(form.description) }}
                </div>
            </div>
        </div>
    </div>

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

{% block localjavascript %}
    $('#mymodal').on('hidden.bs.modal', function () {
        var imgSrc = $("#blogarticle_image_img").attr('src');
        $("#blogarticle_image_img").attr('src',imgSrc);
    }); 
{% endblock %}
