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

{% block javascripts %}
    <script>
        $(document).ready(function() {
            $(".btn-motif").fancybox();
        });
    </script>
{% endblock javascripts %}

{% trans_default_domain 'form' %}

{% block body %}
    <a href="{{ path('admin_mer_itdlc_export') }}" class="btn btn-export">Exporter les demandes</a>
    <h2>Mise en relation automatique </h2>
    <table class="tableBo">
        <thead>
            <tr>
                <td></td>
                <td>Alerte</td>
                <td>{{ 'form.academy.label'|transchoice(1) }}</td>
                <td>{{ 'form.teacher.label'|transchoice(1) }}</td>
                <td>{{ 'form.email.label'|transchoice(1) }} {{ 'form.teacher.label'|transchoice(1) }}</td>
                <td>{{ 'form.engineer.label'|transchoice(1) }}</td>
                <td>{{ 'form.email.label'|transchoice(1) }} {{ 'form.engineer.label'|transchoice(1) }}</td>
                <td>{{ 'form.profile.engineer.company.name.label'|transchoice(1) }}</td>
                <td>{{ 'form.merITDLC.dateMER.label'|trans }}</td>
            </tr>

        </thead>
        {% for m in mers %}
            <tr>
                <td> {%  if m.comment is not empty %}
                        <a class="btn-motif" data-fancybox-type="inline" href="#details-{{ m.id }}"><svg class="icon "><title>Aide</title><use xlink:href="/front/images/svg/symbol/icons-aH4uwG5c1f6a6a.svg#info"></use></svg></a>
                        <div style="display:none" id="details-{{ m.id }}"><strong>Motif</strong>:<br/><br/>{{ m.comment }}</div>
                    {% endif %}</td>
                {% set color = 'none' %}
                {% set title = ' ' %}

                {% if m.answer is not null %}
                    {% if m.answer == 'autre' %}
                        {% set color = 'blue' %}
                        {% set title = 'Autres dates' %}
                    {% elseif m.answer == 'non' %}
                        {% set color = 'yellow' %}
                        {% set title = 'Refusé' %}
                     {% elseif m.answer == 'date1' or m.answer == 'date2' or m.answer == 'date3' %}
                        {% set color = 'green' %}
                        {% set title = 'Accepté' %}
                    {% endif %}
                {% elseif (m.createdAt < date('-10days') ) %}
                    {% set color = 'black' %}
                    {% set title = 'Pas de réponse après 10 jours' %}
                {% elseif (m.createdAt < date('-5days') and m.createdAt >= date('-10days')) %}
                    {% set color = 'red' %}
                    {% set title = 'Pas de réponse après 5 jours' %}

                {% endif %}

                <td title="{{ title }}" style="background: {{ color }}">
                    &nbsp;
                </td>
                <td>
                    {{ m.ope.prof.academy }}
                </td>
                <td>
                    {{- m.ope.prof.fullname -}}
                </td>
                <td>
                    {{ m.ope.prof.email }}
                </td>
                <td>
                    {%- if m.inge is not null %}{{ m.inge.fullname }}{% endif %}
                </td>
                <td>
            {%- if m.inge is not null %}{{ m.inge.email }}{% endif %}
                </td>
                <td>
                    {%- if m.inge is not null and m.inge.establishment is not null %}{{ m.inge.establishment.name }}{% endif %}
                </td>
                <td>
                    {{- m.createdAt|date("d/m/Y") -}}
                </td>
            </tr>
        {% endfor %}
    </table>

    {{ include('Admin/Paginator/pagination.html.twig', {pages: pagination|length}) }}
{% endblock %}