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

{% set modalClass = 'pee ope' %}
{% set headerClass = 'bg-la-rioja no-padding' %}
{% set bodyClass = 'no-padding' %}
{% set footerClass = 'no-padding' %}

{% block header %}
    <div class="container">
        <div class="row">
            <div class="col-lg-6">
                <div class="padding">
                    <div class="row">
                        {% if ope.company.logoPath %}
                        <div class="col-md-4">
                            <div class="thumbnail">
                                <img class="float-left img-fluid" src="{{ absolute_url(vich_uploader_asset(ope.company, 'logoFile')|imagine_filter('500L')) }}"/>
                            </div>
                        </div>
                        {% endif %}
                        <div class="col-md">
                            <h3 class="item-title h6 text-no-transform">
                                {{ ope.company|striptags|raw }}
                            </h3>

                            <p class="location"><em>{{ ope.site|striptags|raw }}</em></p>

                            <p class="baseline">{{ ope.title }}</p>

                            <p class="address">{{ ope.address }} <br />{{ ope.zipcode }} {{ ope.city }}</p>

                            <p class="academy">Académie de {{ ope.academy }}</p>

                            {% if ope.company.website %}
                            <p class="website"><a class="url" href="{{ ope.company.website }}">{{ ope.company.website|replace({'https://':'', 'http://':''}) }}</a></p>
                            {% endif %}
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-lg-6 d-none d-lg-flex has-bg-image"{% if ope.siteImage1Path %} style="background-image: url({{ absolute_url(vich_uploader_asset(ope, 'siteImage1File')|imagine_filter('500L'))|replace({' ' : '%20'}) }})"{% endif %}>&nbsp;</div>
        </div>
    </div>
{% endblock %}

{% block body %}
    <div class="container">
        <div class="row">
            <div class="col-lg-8 bg-white col-left">
                <div class="padding">
                    <div class="row">
                        <div class="col-md-10">
                            <div class="block">
                                <h2 class="h3">Présentation</h2>
                                {% if ope.company.description %}
                                <div class="description">{{ ope.company.description|nl2br }}</div>
                                {% endif %}
                                <div class="presentation">{{ ope.presentation|nl2br }}</div>
                            </div>

                            <div class="block">
                                <h2 class="h3">Visite</h2>
                                <div class="visit">{{ ope.visit|nl2br }}</div> 
                            </div>

                            {% if ope.quoteContent %}
                            <div class="block quotation">
                                <p class="quote">{{ include('Front/_component/icon.html.twig', {id: 'quote', class:'icon-quote'}) }}{{ ope.quoteContent }}</p>
                                <p class="text-right">
                                    <strong>{{ ope.quoteAuthor }}</strong><br/>
                                    <strong>{{ ope.quoteAuthorJob }}</strong>
                                </p>
                            </div>
                            {% endif %}

                            {% if ope.partner and ope.partner.logoPath %}
                            <div class="block partnership">
                                <h2 class="h3">{{ 'sentence.pee.print.partnership'|trans([], 'sentence') }}</h2>
                                <img alt="{{ ope.partner.name }}" class="main-article--partner-logo img-fluid" src="{{ absolute_url(vich_uploader_asset(ope.partner, 'logoFile')|imagine_filter('148L')) }}" />
                            </div>
                            {% endif %}

                            <div class="text-right">
                                <a class="btn btn-theme btn-lg" href="{{ path('operation_pee_download', {id: ope.id}) }}">
                                    {{ 'action.download.pdf'|trans({}, 'action') }}
                                </a>
                            </div>
                        </div>
                        <div class="col-md-2 text-right">
                            {% if ope.category %}
                                <figure class="category-pee text-center">
                                    <div class="category-pee--image bg-la-rioja">
                                        {% if ope.category.logoPath is not null %}
                                            {{ file_get_contents(vich_uploader_asset(ope.category, 'logoFile')) }}
                                        {% endif %}
                                    </div>
                                    <figcaption class="category-pee--caption color-la-rioja">{{ ope.category }}</figcaption>
                                </figure>
                            {% endif %}
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-lg-4 bg-mercury col-right">
                <div class="padding">
                    <div class="text-center"><p class="state">{{ ope.state|transconst('AppBundle\\Enum\\OperationPEEState') }}</p></div>

                    <p class="placesAvailables">
                        {% set placesAvailable = (ope.nbPeople - placesTaken) < 0 ? 0 : (ope.nbPeople - placesTaken) %}
                        {{ 'sentence.pee.places_available'|transchoice(placesAvailable, {}, 'sentence') }}
                    </p>

                    {% if ope.dateVisite is null %}
                        <p class="date">{{ 'sentence.date.operationPEE.missing'|trans({}, 'sentence') }}</p>
                    {% else %}
                        <p class="date">{{ ope.dateVisite|localizeddate('none', 'none', null, null, 'EEEE dd MMMM YYYY') }}</p>
                        <p class="time">{{ ope.startTime|date("H\\hi") }} - {{ ope.endTime|date("H\\hi") }}</p>
                    {% endif %}

                    <p class="namely">{{ ope.namely }}</p>

                    <h2 class="h3">Conditions d'accès</h2>
                    {% if ope.audience %}
                        <p><strong class="color-theme">{{ 'form.audience.label'|trans({}, 'form') }} : </strong> {{ ope.audience }}</p>
                    {% endif %}
                    <p>
                        <strong class="color-theme">Info : </strong> 
                        {% if ope.urlExternalRegistration %}
                            {%- set link -%}
                                <a href="{{ ope.urlExternalRegistration }}">{{ ope.urlExternalRegistration }}</a>
                            {%- endset -%}
                            {{-
                                'sentence.registration.paf'|trans({
                                    '%highlight_start%': '<strong>',
                                    '%highlight_end%': '</strong>',
                                    '%link%': link
                                }, 'sentence')|raw
                            -}}
                            <br/>
                        {% endif %}
                        {{
                            ('sentence.registration.cgenial.' ~ (ope.urlExternalRegistration ? 'after_paf' : 'mandatory'))|trans({
                                '%date%': '<strong>' ~ ope.publish|localizeddate('none', 'none', null, null, 'dd MMMM') ~ '</strong>',
                                '%link%': 'de Cgénial'
                            }, 'sentence')|raw
                        }}
                    </p>
                    <p><strong class="color-theme">Prix : </strong> {{ 'form.visit.free.label'|transchoice(2, {}, 'form') }}</p>
                </div>
            </div>
        </div>
    </div>

    <script type="text/javascript">
    var widowsList = $('.cgenial-modal .date');
		
		widowsList.each(function () {
			var wordArray = $(this).text().split(" ");
			if (wordArray.length > 2) {
				$(this).html($(this).html().replace(wordArray[wordArray.length - 2] + " " + wordArray[wordArray.length - 1], wordArray[wordArray.length - 2] + "&nbsp;" + wordArray[wordArray.length - 1]));
			}
        });

    var ope_reference_select = $('#ope_{{ ope.id }}_select');

    if (ope_reference_select.length > 0) {
        var ope_modal_select = ope_reference_select.clone().attr('id','modal_ope_{{ ope.id }}_select').removeClass('btn-sm').addClass('btn-lg').data('trigger', '#ope_{{ ope.id }}_select');

        $('.cgenial-modal .col-right .padding').append(ope_modal_select);

        ope_modal_select.wrap('<div class="modal-actions text-center"></div>');

        ope_modal_select.click(function() {

            var target = $(this).data('trigger');

            $(target).trigger('click');
            
            if ($.fancybox) {
                $.fancybox.close();
            }
        })
    }
    </script>
{% endblock %}