{% 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>
                            {% if content.getFieldValue('localiser_lieu').destinationContentId %}
                                {% set lieu = load_content_by_content_id(content.getFieldValue('localiser_lieu').destinationContentId) %}
                            {% endif %}
                            {% if not ez_is_field_empty(content, 'adresse') or (lieu is defined and lieu and not ez_is_field_empty(lieu, 'adresse')) or
                                    not ez_is_field_empty(content, 'code_postal') or (lieu is defined and lieu and not ez_is_field_empty(lieu, 'code_postal')) or
                                    not ez_is_field_empty(content, 'commune') or (lieu is defined and lieu and not ez_is_field_empty(lieu, 'commune'))
                            %}
                                <strong>Lieu</strong>
                                <p>
                                    {% if not ez_is_field_empty(content, 'adresse') %}
                                        {{ ez_render_field(content, 'adresse') }}<br>
                                    {% elseif lieu is defined and not ez_is_field_empty(lieu, 'adresse') %}
                                        {{ ez_content_name(lieu) }}<br>
                                        {{ ez_render_field(lieu, 'adresse') }}<br>
                                    {% endif %}
                                    {% if not ez_is_field_empty(content, 'code_postal') %}
                                        {{ ez_render_field(content, 'code_postal') }}
                                    {% elseif lieu is defined and not ez_is_field_empty(lieu, 'code_postal') %}
                                        {{ ez_render_field(lieu, 'code_postal') }}
                                    {% endif %}

                                    {% if not ez_is_field_empty(content, 'commune') %}
                                        {{ ez_render_field(content, 'commune') }}<br>
                                    {% elseif lieu is defined and not ez_is_field_empty(lieu, 'commune') %}
                                        {{ ez_render_field(lieu, '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 not ez_is_field_empty(content, 'geolocalisation')  or not ez_is_field_empty(content, 'localiser_lieu') %}
                    {% if not ez_is_field_empty(content, 'geolocalisation') %}
                        {% set latitude = content.getFieldValue('geolocalisation').latitude %}
                        {% set longitude = content.getFieldValue('geolocalisation').longitude %}
                    {% elseif content.getFieldValue('localiser_lieu').destinationContentId %}
                        {% set lieu = load_content_by_content_id(content.getFieldValue('localiser_lieu').destinationContentId) %}
                        {% set latitude = lieu.getFieldValue('geolocalisation').latitude %}
                        {% set longitude = lieu.getFieldValue('geolocalisation').longitude %}
                    {% endif %}
                    {% 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 %}