{% extends 'Front/layout.html.twig' %}

{% import 'Front/Default/macro.html.twig' as m %}

{% set constOperationPEEStateOpen = constant('AppBundle\\Enum\\OperationPEEState::OPEN') %}

{% set metatitle = maincontent.metatitle ? maincontent.metatitle : maincontent.menu %}
{% set metadescription = maincontent.metadescription ? maincontent.metadescription : null %}
{% block metaOpengraph %}
    <meta property="og:url" content="{{ app.request.getSchemeAndHttpHost() ~ path(app.request.attributes.get('_route'), app.request.attributes.get('_route_params')) }}">
    <meta property="og:type" content="article">
    <meta property="og:locale" content="{{ app.request.locale }}">
    <meta property="og:image" content="">
    <meta property="og:title" content="{{ maincontent.title }}">
    <meta property="og:description" content="{{ maincontent.article|striptags }}">
{% endblock %}

{% set bodyClass = 'presentation ' ~ maincontent.menu.class %}

{% block body %}
    <div class="row">
        <article class="content presentation col">
            <div class="content-text">
                {{ maincontent.article|replace_custom_keys|raw  }}<br/>
            </div>

            <div id="accordion">
                {#% if operationsPEE|length > 0 %}
                    {% set earliestYear = date()|date('Y') %}
                    {% for o in operationsPEE %}
                        {% if o.dateVisite|date('Y') < earliestYear %}
                            {% set earliestYear = o.dateVisite|date('Y') %}
                        {% endif %}
                    {% endfor %}
                    <h3>
                        Liste des sites de <em>Professeurs en entreprise</em> {{ earliestYear }}
                        {{ m.svg({id:'arrow--arrow-37'}) }}
                    </h3>
                    <div id="operationspee">
                        <div class="operationspee-legend">
                            <h4>Légende</h4>
                            <ul class="operationspee-legend-list">
                                <li class="operationpee-state-open">Opération ouverte&nbsp;: vous pouvez vous y inscrire.</li>
                                <li class="operationpee-state-open--full">Opération ouverte, complète&nbsp;: vous pouvez toujours vous y inscrire, mais vous figurerez alors en liste d'attente.</li>
                                <li class="operationpee-state-fenced">Opération clôturée&nbsp;: tous les inscrits ont été validés et vous ne pouvez par conséquent plus vous y inscrire.</li>
                                <li class="operationpee-state-cancelled">Opération annulée&nbsp;: elle n'aura finalement pas lieu. Par conséquent, vous ne pouvez pas vous y inscrire.</li>
                            </ul>
                        </div>
                        {% set operationPEEAcademyCurrent = null %}

                        {% for o in operationsPEE %}
                            {% if o.academy != operationPEEAcademyCurrent %}
                                {% if operationPEEAcademyCurrent != null %}</ul>{% endif %}
                                {% set operationPEEAcademyCurrent = o.academy %}
                                <h4>Académie {% if operationPEEAcademyCurrent|lower|first in ['a', 'e', 'i', 'o', 'y'] %}d'{% else %}de {% endif %}<em>{{ operationPEEAcademyCurrent }}</em>&nbsp;:</h4>
                                <ul class="operationspee-list">
                            {% endif %}
                                <li class="operationpee-state-{{ o.state }}{% if constOperationPEEStateOpen == o.state and o.nbPeople - o.demandepee|length <= 0 %}--full{% endif %}">
                                    {% spaceless %}
                                        <span
                                            title="Opération {{ ('word.state.operationPEE.' ~ o.state ~ '.label')|trans({}, 'word')|lower }}{% if constOperationPEEStateOpen == o.state and o.nbPeople > 0 and o.nbPeople - o.demandepee|length <= 0 %}, complète{% endif %}"
                                        >Opération <strong>{{ ('word.state.operationPEE.' ~ o.state ~ '.label')|trans({}, 'word')|lower }}</strong>&nbsp;: </span>
                                        {%- if o.dateVisite is null %}
                                            {{ 'sentence.date.operationPEE.missing'|trans({}, 'sentence') }}
                                        {%- else %}
                                            le {{ o.dateVisite|date("d/m/Y") }}
                                        {%- endif %}

                                        à {{ o.company }}, {{ o.city }}.
                                        <a href="{{ path('operation_pee_download', {id: o.id}) }}" title="Voir la fiche descriptive de l'opération">
                                            Fiche descriptive (PDF)
                                        </a>
                                    {% endspaceless %}
                                </li>
                        {% endfor %}
                    </div>
                {% endif %#}
                {% for content in contents %}
                    <h3>
                        {{ content.title }}
                        {{ m.svg({id: 'arrow--arrow-37'}) }}
                    </h3>
                    <div>
                        {{ content.article|replace_custom_keys|raw  }}<br/>
                        {% if content.picture != '' %}
                            <img src="{{ asset(content.getWebPath())|url_encode }}" alt="{{ content.title }}" width="50"/>
                        {% endif %}
                    </div>
                {% endfor %}
            </div>

            {#% if pictures != null or videos != null %}
                <div class="galleries">
                    <ul class="galleries-tabs">
                        {% if pictures != null %}
                            <li><a class="btn current on" href="#gallery-pictures">Photos</a></li>
                        {% endif %}
                        {% if videos != null %}
                            <li><a class="btn" href="#gallery-videos">Vidéos</a></li>
                        {% endif %}
                    </ul>

                    <div class="clear"></div>

                    {% for picture in pictures %}
                        {% if loop.first %}
                            <ul class="gallery gallery-pictures on" id="gallery-pictures">
                        {% endif %}

                        <li class="item">
                            <figure class="thumbnail">
                                <a data-fancybox="gallery-pictures" data-type="image" href="{{ asset(picture.getWebPathPicture()) }}" title="{{ picture.title }}">
                                    <img src="{{ asset(picture.getWebPathPicture())|imagine_filter('500L') }}" alt="{{ picture.title }}">
                                </a>
                            </figure>
                        </li>

                        {% if loop.last %}
                            </ul>
                        {% endif %}
                    {% endfor %}

                    {% for video in videos %}
                        {% if loop.first %}
                            <ul class="gallery gallery-videos{% if pictures == null %} on{% endif %}" id="gallery-videos">
                        {% endif %}

                        <li class="item"te>
                            {{
                                include('Front/_component/video.html.twig', {
                                    id: video.path,
                                    caption: video.title
                                })
                            }}
                        </li>

                        {% if loop.last %}
                            </ul>
                        {% endif %}
                    {% endfor %}
                </div>
            {% endif %#}
        </article>
        
        {% include "Front/_part/sidebar.html.twig" %}
    </div>
    {% set presentation_bloc_1 = render(controller('AppBundle:Render:module', { position:'presentation_after_content_bloc_1' })) %}
    {% set presentation_bloc_2 = render(controller('AppBundle:Render:module', { position:'presentation_after_content_bloc_2' })) %}
    {% set presentation_bloc_3 = render(controller('AppBundle:Render:module', { position:'presentation_after_content_bloc_3' })) %}

    {% if presentation_bloc_1 or presentation_bloc_2 or presentation_bloc_3 %}
    <div class="after_content row justify-content-center">
        <div class="col-sm-6 col-lg-4">
            {{ render(controller('AppBundle:Render:module', { position:'presentation_after_content_bloc_1' })) }}
        </div>
        <div class="col-sm-6 col-lg-4">
                {{ render(controller('AppBundle:Render:module', { position:'presentation_after_content_bloc_2' })) }}
        </div>
        <div class="col-sm-6 col-lg-4">
            {{ render(controller('AppBundle:Render:module', { position:'presentation_after_content_bloc_3' })) }}
        </div>
    </div>
    {% endif %}
{% endblock %}

{% block before_body %}
    {% set pageHeaderPicture = ( maincontent.picture ? asset(maincontent.getWebPath()) : null ) %}
    {% set pageHeaderTitle = maincontent.title %}
    {% set pageHeaderIntroduction = maincontent.introduction|replace_custom_keys|raw %}
    {% include "Front/_part/page-header.html.twig" %}
    {{ render(controller('AppBundle:Render:module', { position:'before_body' })) }}
{% endblock %}

{% block after_body %} 
    {{ render(controller('AppBundle:Render:module', { position:'after_body' })) }}
{% endblock %}