{% extends default_layout is defined ? default_layout : "AyalineCollectiviteBundle::pagelayout.html.twig" %}

{% block content %}
    <div class="introduction">
        <div class="container">
            <h1 {% if get_class_identifier(location.parentLocationId) == "agenda" %} class="with-link"{% endif %}>{{ ez_render_field(content, 'titre') }}</h1>
            {% if get_class_identifier(location.parentLocationId) == "agenda" %}
                {% set uri = app.request.query.has('uri') ? app.request.query.get('uri') : '' %}
                {% set url = uri ? uri : path( 'ez_urlalias', {'locationId': location.parentLocationId } ) %}
                <a href="{{ url }}" class="voir-plus">&gt; Retour à la liste</a>
            {% endif %}
            <h2>
                {{ ez_render_field(content, 'thematiques') }}
                {% if not ez_is_field_empty( content, "sous_titre" ) %}
                    - {{ ez_render_field(content, 'sous_titre') }}
                {% endif %}
            </h2>

            <div class="event-infos-detail">
                {% set AgendaRoot = load_content_by_location_id(location.parentLocationId) %}

                <time datetime="{{ ez_field_value(content, "date_debut")|localizeddate('none', 'none', app.request.locale, null, "dd/MM/yyyy") }}">
                    {% if content.fields.date_debut is defined and not ez_is_field_empty( content, "date_debut" )
                    and content.fields.date_fin is defined and not ez_is_field_empty( content, "date_fin" )
                    and content.getFieldValue('date_debut').date != content.getFieldValue('date_fin').date %}
                        Du
                    {% endif %}
                    {% if content.fields.date_debut is defined and not ez_is_field_empty( content, "date_debut" ) %}
                    {% if content.fields.date_fin is defined and not ez_is_field_empty( content, "date_fin" )  and content.getFieldValue('date_debut').date != content.getFieldValue('date_fin').date%}
                        {% set dateDebut = ez_field_value(content, "date_debut")|localizeddate('none', 'none', app.request.locale, null, "cccc dd LLLL yyyy") %}
                    {% else %}
                        {% set dateDebut = ez_field_value(content, "date_debut")|localizeddate('none', 'none', app.request.locale, null, "cccc dd LLLL yyyy")|capitalize %}
                    {% endif %}
                    {{ dateDebut }}</time>
                {% if content.fields.date_fin is defined and not ez_is_field_empty( content, "date_fin" )  and content.getFieldValue('date_debut').date != content.getFieldValue('date_fin').date%}
                    <time datetime="{{ ez_field_value(content, "date_fin")|localizeddate('none', 'none', app.request.locale, null, "dd/MM/yyyy") }}">
                        au {{ ez_field_value(content, "date_fin")|localizeddate('none', 'none', app.request.locale, null, "cccc dd LLLL yyyy") }}
                    </time>
                {% endif %}
                {% endif %}

                {% if AgendaRoot and AgendaRoot.fields.mode_escale is defined and not ez_is_field_empty(AgendaRoot, 'mode_escale') %}
                    <ul class="event-infos">
                        {% if content.fields.horaire is defined and not ez_is_field_empty(content, 'horaire')  %}
                            <li class="time-info">
                                <span class="icon-time"></span>
                                <span class="title-time">{{ ez_render_field(content, 'horaire') }}</span>
                            </li>
                        {% endif %}
                        {% if content.fields.abonnement is defined and not ez_is_field_empty(content, 'abonnement') %}
                            <li class="tarif-info">
                                <span class="icon-abonnement"></span>
                                <span class="title-tarif">Tarif réduit</span>
                            </li>
                        {% endif %}
                    </ul>
                {% endif %}
            </div>

            {% if content.fields.resume is defined and not ez_is_field_empty(content, 'resume') %}
                <div class="ezxmltext-field">
                    <p>
                        {{ ez_render_field(content, "resume") }}
                    </p>
                </div>
            {% endif %}
        </div>
    </div>

    <div class="container">
        <div class="row content-row">
            <section class="col-md-8">
                <article>
                    {% if content.getFieldValue( 'afficher_vignette_detail' ).bool and content.getFieldValue( 'vignette' ).destinationContentId is defined and content.getFieldValue( 'vignette' ).destinationContentId  %}
                        <div class="img-desc">
                            {% if content.getFieldValue( 'vignette' ).destinationContentId is defined and content.getFieldValue( 'vignette' ).destinationContentId  %}
                                {% set imageContent = load_content_by_content_id(content.getFieldValue('vignette').destinationContentId) %}
                                {% if imageContent is not null %}
                                    {{ ez_render_field( imageContent, "image", { 'template': 'AyalineEzAgendaCollectivitesBundle:fields:event_ezimage.html.twig', 'parameters': { 'alias': 'line_event_agenda' } } ) }}
                                {% endif %}
                            {% endif %}
                        </div>
                    {% endif %}

                    {{ ez_render_field( content, "description" ) }}
                    <div class="clearfix"></div>
                </article>

                <div class="bloc-detail-infos">
                    <h3>Infos pratiques</h3>
                    <ul>
                        <li><strong>Date</strong>
                            <p>
                                <time datetime="{{ ez_field_value(content, "date_debut")|localizeddate('none', 'none', app.request.locale, null, "dd/MM/yyyy") }}">
                                    {% if content.fields.date_debut is defined and not ez_is_field_empty( content, "date_debut" )
                                    and content.fields.date_fin is defined and not ez_is_field_empty( content, "date_fin" )
                                    and content.getFieldValue('date_debut').date != content.getFieldValue('date_fin').date %}
                                        Du
                                    {% endif %}
                                    {% if content.fields.date_debut is defined and not ez_is_field_empty( content, "date_debut" ) %}
                                    {% if content.fields.date_fin is defined and not ez_is_field_empty( content, "date_fin" )  and content.getFieldValue('date_debut').date != content.getFieldValue('date_fin').date%}
                                        {% set dateDebut = ez_field_value(content, "date_debut")|localizeddate('none', 'none', app.request.locale, null, "cccc dd LLLL yyyy") %}
                                    {% else %}
                                        {% set dateDebut = ez_field_value(content, "date_debut")|localizeddate('none', 'none', app.request.locale, null, "cccc dd LLLL yyyy")|capitalize %}
                                    {% endif %}

                                    {{ dateDebut }}</time>

                                {% if content.fields.date_fin is defined and not ez_is_field_empty( content, "date_fin" ) and content.getFieldValue('date_debut').date != content.getFieldValue('date_fin').date %}
                                    <time datetime="{{ ez_field_value(content, "date_fin")|localizeddate('none', 'none', app.request.locale, null, "dd/MM/yyyy") }}">
                                        au {{ ez_field_value(content, "date_fin")|localizeddate('none', 'none', app.request.locale, null, "cccc dd LLLL yyyy") }}
                                    </time>
                                {% endif %}
                                {% else %}
                                    {{ content.contentInfo.publishedDate|localizeddate('none', 'none', app.request.locale, null, "cccc dd LLLL yyyy") }}
                                {% endif %}
                            </p>
                        </li>
                        {% if not ez_is_field_empty(content, 'horaire') %}
                            <li><strong>Heure</strong><p>{{ ez_render_field(content, 'horaire') }}</p></li>
                        {% endif %}
                        <li>
                            {% set coordonneesEvent = get_coordonnees_event(content.id) %}
                            {% set lieuContent = coordonneesEvent.LieuCoordonnes %}
                            {% set lieuContentName = ez_content_name(lieuContent)|trim %}

                            {% if lieuContent and (not ez_is_field_empty(lieuContent, 'adresse') or not ez_is_field_empty(lieuContent, 'code_postal') or not ez_is_field_empty(lieuContent, 'commune')) %}
                                {% set classId = get_class_identifier(lieuContent.contentInfo.mainLocationId) %}
                                <strong>Lieu</strong>
                                <p>
                                    {% if not ez_is_field_empty(lieuContent, 'adresse') %}
                                        {% if classId != 'evenement' %}
                                            {{ coordonneesEvent.lieuName }} {% if lieuContentName != coordonneesEvent.lieuName and lieuContentName is not empty %}({{ lieuContentName }}){% endif %}
                                            <br>{% endif %}
                                        {{ ez_render_field(lieuContent, 'adresse') }}<br>
                                    {% endif %}
                                    {% if not ez_is_field_empty(lieuContent, 'code_postal') %}
                                        {{ ez_render_field(lieuContent, 'code_postal') }}
                                    {% endif %}
                                    {% if not ez_is_field_empty(lieuContent, 'commune') %}
                                        {{ ez_render_field(lieuContent, 'commune') }}<br>
                                    {% endif %}
                                </p>
                            {% endif %}
                        </li>

                        <li><strong>Thématique(s)</strong><p>{{ ez_render_field(content, 'thematiques') }}</p></li>

                        {% set parentContent = load_content_by_location_id(location.parentLocationId) %}
                        {% if not ez_is_field_empty(parentContent, 'activer_gestion_type') %}
                            <li><strong>Type(s)</strong><p>{{ ez_render_field(content, 'types') }}</p></li>
                        {% endif %}

                        {% if not ez_is_field_empty(content, 'structure') %}
                            <li><strong>Organisateur</strong><p>{{ ez_render_field(content, 'structure') }}</p></li>
                        {% endif %}
                        {% if not ez_is_field_empty(content, 'site_internet') %}
                            <li><strong>Site web</strong>
                                <p>
                                    {{ ez_render_field(content, 'site_internet' ,{ 'attr': { 'target': '_blank'} } ) }}
                                </p>
                            </li>
                        {% endif %}
                    </ul>
                </div>
                {% if not ez_is_field_empty(content, 'reservation') or not ez_is_field_empty(content, 'tarif_conditions') %}
                    <div class="bloc-detail-infos last">
                        <ul>
                            {% if not ez_is_field_empty(content, 'reservation') %}
                                <li><strong>Réservation</strong>{{ ez_render_field(content, 'reservation') }}</li>
                            {% endif %}
                            {% if not ez_is_field_empty(content, 'tarif_conditions') %}
                                <li><strong>Tarifs et conditions d’accès</strong>{{ ez_render_field(content, 'tarif_conditions') }}</li>
                            {% endif %}
                        </ul>
                    </div>
                {% endif %}


                {% if lieuContent and not ez_is_field_empty(lieuContent, 'geolocalisation') %}
                    {% set latitude = lieuContent.getFieldValue('geolocalisation').latitude %}
                    {% set longitude = lieuContent.getFieldValue('geolocalisation').longitude %}

                    {% set params = [] %}
                    {% set detailCarte = {
                            "url": "",
                            "image": "",
                            "titre": ez_render_field(content, "titre"),
                            "info1": ez_render_field(content, "thematiques"),
                            "info2": "",
                            "info3": {},
                            "latLngs": {
                                'latitude': latitude,
                                'longitude': longitude
                            }
                        }
                    %}
                    {% set params = params|merge([detailCarte]) %}

                    {{ render( controller(
                                "AyalineEzCartographieCollectivitesBundle:Cartographie:map",
                                {
                                    'params': params,
                                }
                            )
                        )
                    }}
                {% endif %}

            </section>

            {% block right_column %}
                {% include 'AyalineCollectiviteBundle:rightColumn:right_column_agenda.html.twig' %}
            {% endblock %}

        </div>
    </div>
{% endblock %}