{% extends 'Admin/layout.html.twig' %}
{%- import 'Admin/Form/macros.html.twig' as m -%}

{% block javascripts %}
    <script>
        $(function() {
            $('#checkbox-informations').on('change', function() {
                var actif = $(this).is(':checked') ? 'true' : 'false',
                    id = $(this).val();

                $.ajax({
                    type: "POST",
                    url: "{{ path('user_actif') }}",
                    data: {
                        id: id,
                        actif: actif,
                        type: 'isValideInfo'
                    },
                    cache: false
                });
            });
        });
    </script>
{% endblock %}

{% block body %}
    <header>
        <ul class="btns">
            <li class="btns-back">
                {{ m.step_back() }}
            </li>
            <li>
                <button class="btn btn-save" form="form-demandepeeedit">
                    {{ 'action.save'|trans({}, 'action') }}
                </button>
            </li>
        </ul>

        <h1>Modifier demande PEE</h1>
    </header>

    <h3>État de la demande</h3>
    <div style="float: left; ">
        <strong>Date du dépôt :</strong> {{ ope.created|date('d/m/Y') }}<br/>
        <strong>Demandeur :</strong> {{ ope.cuser.lastname }}, {{ ope.cuser.firstname }}<br/>
            {% if ope.cuser.categoryJob is not empty %}{{ ope.cuser.categoryJob|transconst('AppBundle\\Enum\\UserJobTeacherCategory') }} / {% endif %}{% if ope.cuser.jobOther is not empty %}{{ ope.cuser.jobOther }}{% else %}{{ ope.cuser.job|transconst('AppBundle\\Enum\\UserJobTeacher') }}{% endif %}<br/>
                    {{ ope.cuser.email }}<br/>
                    {{ ope.cuser.phone }}<br/><br/>
        <strong>Opération demandée :</strong>
                    {{
                        ope.operationpee.dateVisite is not null
                            ? ope.operationpee.dateVisite|date('d/m/Y')
                            : 'sentence.date.operationPEE.missing'|trans({}, 'sentence')
                    }}<br/>
                    {{ ope.operationpee.company }}<br/>
                    {{ ope.operationpee.site }}<br/><br/>
    </div>

    <div style="border-left: 1px solid #ccc; float: right; padding: 0 20px; width: 600px;">
        <p>
            <label for="checkbox-informations"><strong>Informations validées&nbsp;:</strong></label>
            <input{% if ope.cuser.isvalideinfo %} checked="checked"{% endif %} id="checkbox-informations" type="checkbox" value="{{ ope.cuser.id }}"/>
            <span class="checkbox"></span>
        </p>

        <p><strong>Carte d'identité :</strong></p>

        <table class="table-simple" id="table-ci">
            <thead>
                <tr>
                    <td>Recto</td>
                    <td>Verso</td>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>
                        {% if ope.cuser.identityCard1 is not null %}
                            <a href="{{ url('secure_user_file', {filename:ope.cuser.identityCard1, ownerId:ope.cuser.id}) }}" target="_blank">
                                {% if ope.cuser.identityCard1 ends with '.jpg'
                                        or ope.cuser.identityCard1 ends with '.jpeg'
                                        or ope.cuser.identityCard1 ends with '.png'
                                        or ope.cuser.identityCard1 ends with '.gif'
                                %}
                                    <img src="{{ url('secure_user_file', {'filename':ope.cuser.identityCard1, ownerId:ope.cuser.id}) }}" width="200" />
                                {% else %}
                                    Voir le fichier
                                {% endif %}
                            </a>
                        {% else %}
                            Aucun fichier transféré
                        {% endif %}
                    </td>
                    <td>
                        {% if ope.cuser.identityCard2 is not null %}
                            <a href="{{ url('secure_user_file', {filename:ope.cuser.identityCard2, ownerId:ope.cuser.id }) }}" target="_blank">
                                {% if ope.cuser.identityCard2 ends with '.jpg'
                                        or ope.cuser.identityCard2 ends with '.jpeg'
                                        or ope.cuser.identityCard2 ends with '.png'
                                        or ope.cuser.identityCard2 ends with '.gif'
                                %}
                                    <img src="{{ url('secure_user_file', {filename:ope.cuser.identityCard2, ownerId:ope.cuser.id }) }}" width="200" />
                                {% else %}
                                    Voir le fichier
                                {% endif %}
                            </a>
                        {% else %}
                            Aucun fichier transféré
                        {% endif %}
                    </td>
                </tr>
            </tbody>
        </table>
        <p><strong>Date de validité&nbsp;:</strong>{% if  ope.cuser.identityCardValidity is not empty %} {{ ope.cuser.identityCardValidity|date('d/m/Y') }} {% endif %}</p>
        <p><strong>Pointure&nbsp;:</strong> {{ ope.cuser.shoeSize }}</p>
        <p><strong>Mail chef établissement&nbsp;:</strong> {{ ope.cuser.bossemail }}</p>
    </div>

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

    <table class="tableBo">
        <thead>
            <tr>
                <td>Nombre total de places</td>
                <td>Inscrits</td>
                <td>Pré-inscrits</td>
                <td>Liste d'attente</td>
                <td>Désistements</td>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>{{ ope.operationpee.nbpeople }}</td>
                <td>{{ countDemandesByState[constant('AppBundle\\Enum\\DemandePEEState::REGISTERED')] }}</td>
                <td>{{ countDemandesByState[constant('AppBundle\\Enum\\DemandePEEState::PREREGISTERED')] }}</td>
                <td>{{ countDemandesByState[constant('AppBundle\\Enum\\DemandePEEState::WAITING')] }}</td>
                <td>{{ countDemandesByState[constant('AppBundle\\Enum\\DemandePEEState::WITHDRAWAL')] }}</td>
            </tr>
        </tbody>
    </table>

    <div class="borderBottom"></div>

    {{ form_start(form, {'attr':{'id':'form-demandepeeedit'}}) }}
        {{ form_errors(form) }}
        {{ form_row(form.state) }}
        {{ form_row(form.type, {attr:{class:'form-row-childs-inline'}}) }}
    {{ form_end(form) }}

    <ul class="btns">
        <li>
            <button class="btn btn-save" form="form-demandepeeedit">
                {{ 'action.save'|trans({}, 'action') }}
            </button>
        </li>
    </ul>
{% endblock %}
