{% 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">
                <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 %}

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

            <div class="ezxmltext-field">
                <p>
                    {{ ez_render_field(content, "resume") }}
                </p>
            </div>
        </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">
                            {{ ez_render_field( content, "vignette", { 'template': 'AyalineEzAgendaCollectivitesBundle:fields:event_ezobjectrelation.html.twig', 'parameters': { 'alias': 'line_event_agenda' } } ) }}
                        </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 lieuContent = get_coordonnees_event(content.id) %}
                            {% 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' %}{{ ez_content_name(lieuContent) }}<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 %}