<!-- templates/registration/login.html -->
{% extends 'tournaments/base.html' %}
{% block head_title %} Connexion {% endblock %}
{% block first_title %} Padel Club {% endblock %}
{% block second_title %} Connexion {% endblock %}

{% block content %}
{% load static %}
{% load tz %}

<div class="grid-x">
<div class="bubble">
    <div class="cell medium-6 large-6 padding10">
        {% if form.non_field_errors %}
        <div class="alert alert-error">
            {% for error in form.non_field_errors %}
                <p>{{ error }}</p>
            {% endfor %}

            {% for field in form %}
                {% for error in field.errors %}
                    <p>{{ error }}</p>
                {% endfor %}
            {% endfor %}
        </div>
        {% endif %}

        <!-- Check if there's an inactive user email in session -->
        {% if inactive_user_email %}
            <div style="margin-top: 15px; padding: 15px; background-color: #f8f9fa; border: 1px solid #dee2e6; border-radius: 5px;">
                <p><strong>Besoin d'aide ?</strong></p>
                <p>Si vous n'avez pas reçu l'e-mail d'activation ou si le lien a expiré, vous pouvez en demander un nouveau :</p>

                <form method="post" action="{% url 'resend-activation' %}" style="margin-top: 10px;">
                    {% csrf_token %}
                    <input type="hidden" name="username_or_email" value="{{ inactive_user_email }}">
                    {% if request.GET.next %}
                        <input type="hidden" name="next" value="{{ request.GET.next }}">
                    {% endif %}
                    <button type="submit" class="rounded-button" style="background-color: #28a745; margin-top: 10px;">
                        Renvoyer le lien d'activation
                    </button>
                </form>

                <p style="margin-top: 10px; font-size: 14px; color: #6c757d;">
                    Le lien sera envoyé à : <strong>{{ inactive_user_email }}</strong>
                </p>
            </div>
        {% endif %}

        <form method="post" action="{% url 'custom-login' %}">
            {% csrf_token %}
            {% if request.GET.next and 'reset' not in request.GET.next and 'password_reset' not in request.GET.next %}
                <input type="hidden" name="next" value="{{ request.GET.next }}">
            {% endif %}
                <label for="username">Identifiant ou e-mail </label>
            <input type="text" name="username" id="username" required>

            <label for="password">Mot de passe :</label>
            <input type="password" name="password" id="password" required>
            <button type="submit" class="rounded-button">Se connecter</button>

            <p>
                <a href="{% url 'password_reset' %}" class="styled-link">Mot de passe oublié ?</a>
            </p>

        </form>
        <p>Pas encore de compte ? <a href="{% url 'signup' %}" class="styled-link">Créez le tout de suite !</a></p>
    </div>
</div>
</div>

{% endblock %}
