{% extends 'base.html.twig' %}

{% block title %}Liste des Candidatures{% endblock %}

{% block body %}
    <div class="max-w-2xl mx-auto mt-8">
        <h2 class="text-3xl font-semibold text-center mb-8 text-gray-800">Candidatures reçues</h2>

        {% for app in applications %}
            <div class="border border-gray-200 rounded-2xl p-6 shadow-md bg-white space-y-2">
                <p><span class="font-semibold text-gray-700">Annonce :</span> {{ app.application.title }}</p>
                <p><span class="font-semibold text-gray-700">Candidat :</span> {{ app.intern.firstName }} {{ app.intern.lastName }}</p>
                <p><span class="font-semibold text-gray-700">Date :</span> {{ app.applicationDate|date('d/m/Y') }}</p>
                <p><span class="font-semibold text-gray-700">Statut :</span> {{ app.status|capitalize }}</p>

                <a href="{{ path('app_profile_visit', { id: app.intern.id }) }}"
                   class="inline-block mt-3 bg-teal-500 hover:bg-teal-600 text-white px-4 py-2 rounded shadow">
                    Voir le profil du candidat
                </a>

                {% if app.status == 'En Attente' %}
                    <div class="flex justify-end gap-3 mt-4">
                        <form method="post" action="{{ path('app_employee_update_application_status',
                            {id: app.id, status: 'Acceptée'}) }}">
                            <button type="submit" class="bg-green-500 hover:bg-green-600 text-white px-4 py-2 rounded shadow">
                                Accepter
                            </button>
                        </form>

                        <form method="post" action="{{ path('app_employee_update_application_status',
                            {id: app.id, status: 'Refusée'}) }}">
                            <button type="submit" class="bg-red-500 hover:bg-red-600 text-white px-4 py-2 rounded shadow">
                                Refuser
                            </button>
                        </form>
                    </div>
                {% endif %}
            </div>
        {% else %}
            <p class="text-center text-gray-600">Aucune candidature pour le moment.</p>
        {% endfor %}
    </div>
{% endblock %}
