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

{% block javascripts %}
    <script>
        $(function() {
            $('.fancybox').fancybox({
                'maxHeight': '90%',
                'padding': 0
            });
        });
    </script>
{% endblock %}

{% block body %}
    {# Formulaire de recherche #}
    <form action="{{ path(app.request.attributes.get('_route'), app.request.attributes.get('_route_params')) }}" class="search-admin" method="get">
        <fieldset>
            <div class="search-fields">
                <p>
                    <label for="form_search_email">{{ 'form.contact.email.label'|trans({}, 'form') }}</label>
                    <input id="form_search_email" name="email" type="text" value="{{ search_email }}">
                </p>
                <p>
                    <label for="form_search_category">{{ 'form.contact.category.label'|trans({}, 'form') }}</label>
                    <select id="form_search_category" name="category">
                        <option value="">- {{ 'form.contact.category.all'|trans([], 'form') }} -</option>
                        {% for category in categories %}
                            <option value="{{ category }}"{% if search_category == category %} selected="selected"{% endif %}>
                                {{ ('form.contact.category.' ~ category)|trans([], 'form') }}
                            </option>
                        {% endfor %}
                    </select>
                </p>
                <p>
                    <label for="form_search_subject">{{ 'form.contact.subject.label'|trans({}, 'form') }}</label>                        <select id="form_search_position" name="subject">
                        <option value="">- {{ 'form.contact.subject.all'|trans([], 'form') }} -</option>
                        {% for subject in subjects %}
                            <option value="{{ subject }}"{% if search_subject == subject %} selected="selected"{% endif %}>
                                {{ ('form.contact.subject.' ~ subject)|trans([], 'form') }}
                            </option>
                        {% endfor %}
                    </select>
                </p>
                <p>
                    <label for="form_search_datemin">{{ 'form.contact.created.label'|trans({}, 'form') }} - Début</label>
                    <input id="form_search_datemin" type="text" value="{{ search_datemin }}" class="date" name="datemin"/>
                </p>
                <p>
                    <label for="form_search_datemax">{{ 'form.contact.created.label'|trans({}, 'form') }} - Fin</label>
                    <input id="form_search_datemax" type="text" value="{{ search_datemax }}" class="date" name="datemax"/>
                </p>
            </div>
        </fieldset>
        <p>
            <input class="btn" type="submit" value="{{ 'action.search'|trans({}, 'action') }}" />
        </p>
    </form>

    <table class="tableBo">
            <thead>
                    <td>{{ 'form.contact.firstname.label'|trans({}, 'form') }}</td>
                    <td>{{ 'form.contact.lastname.label'|trans({}, 'form') }}</td>
                    <td>{{ 'form.contact.company.label'|trans({}, 'form') }}</td>
                    <td>{{ 'form.contact.email.label'|trans({}, 'form') }}</td>
                    <td>{{ 'form.contact.category.label'|trans({}, 'form') }}</td>
                    <td>{{ 'form.contact.subject.label'|trans({}, 'form') }}</td>
                    <td>{{ 'form.contact.message.label'|trans({}, 'form') }}</td>
                    <td>{{ 'form.contact.created.label'|trans({}, 'form') }}</td>
                    <td colspan="2">{{ 'word.actions'|trans({}, 'word') }}</td>
                </tr>
            </thead>
            <tbody>
                {% for contact in contacts %}
                    <tr class="delete-element-container">
                        <td><a href="{{ path('admin_contact_view', {'id':contact.id}) }}">{{ contact.firstname|striptags|raw }}</a></td>
                        <td><a href="{{ path('admin_contact_view', {'id':contact.id}) }}">{{ contact.lastname|striptags|raw }}</a></td>
                        <td><a href="{{ path('admin_contact_view', {'id':contact.id}) }}">{{ contact.company|striptags|raw }}</a></td>
                        <td><a href="{{ path('admin_contact_view', {'id':contact.id}) }}">{{ contact.email|striptags|raw }}</a></td>
                        <td><a href="{{ path('admin_contact_view', {'id':contact.id}) }}">{{ ('form.contact.category.' ~ contact.category)|trans({}, 'form') }}</a></td>
                        <td><a href="{{ path('admin_contact_view', {'id':contact.id}) }}">{{ ('form.contact.subject.' ~ contact.subject)|trans({}, 'form') }}</a></td>
                        <td><a href="{{ path('admin_contact_view', {'id':contact.id}) }}">{{ contact.message|striptags|truncate(50, '…')|raw }}</a></td>
                        <td><a href="{{ path('admin_contact_view', {'id':contact.id}) }}">{{ contact.created|date("d/m/Y H:i") }}</a></td>
                        <td class="action">
                            <a class="search" href="{{ path('admin_contact_view', {'id':contact.id}) }}">
                                <span>{{ 'action.edit.label'|trans({}, 'action') }}</span>
                            </a>
                        </td>
                        <td class="action">
                            <a class="delete-element" href="{{ path('admin_contact_delete', {'id':contact.id}) }}">
                                <span>{{ 'action.delete.label'|trans({}, 'action') }}</span>
                            </a>
                        </td>
                    </tr>
                {% else %}
                    <tr>
                        <td colspan="10"></td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>

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