{% extends "base.html" %}
{% load i18n %}

{% block content %}
<section class="py-5">
    <div class="container">
        <div class="mb-4">
            <a href="/" class="btn btn-outline-secondary btn-sm">
                <i class="fa-solid fa-arrow-left me-1"></i> {% trans "Back to Home" %}
            </a>
        </div>
        <div class="row justify-content-center">
            <div class="col-md-5">
                <div class="card shadow">
                    <div class="card-body p-5">
                        <h2 class="text-center mb-4">{% trans "Login" %}</h2>
                        <form method="post">
                            {% csrf_token %}
                            <div class="mb-3">
                                <label class="form-label">{% trans "Username" %}</label>
                                {{ form.username }}
                                {% if form.username.errors %}
                                    {% for error in form.username.errors %}
                                        <div class="text-danger small">{{ error }}</div>
                                    {% endfor %}
                                {% endif %}
                            </div>
                            <div class="mb-3">
                                <label class="form-label">{% trans "Password" %}</label>
                                {{ form.password }}
                                {% if form.password.errors %}
                                    {% for error in form.password.errors %}
                                        <div class="text-danger small">{{ error }}</div>
                                    {% endfor %}
                                {% endif %}
                            </div>
                            
                            <div class="mb-3">
                                <label class="form-label d-block">{{ form.otp_method.label }}</label>
                                <div class="btn-group w-100" role="group">
                                    {% for radio in form.otp_method %}
                                        <input type="radio" class="btn-check" name="{{ form.otp_method.name }}" id="login_{{ radio.id_for_label }}" value="{{ radio.data.value }}" {% if radio.data.selected %}checked{% endif %}>
                                        <label class="btn btn-outline-primary" for="login_{{ radio.id_for_label }}">
                                            {% if radio.data.value == 'whatsapp' %}
                                                <i class="fa-brands fa-whatsapp me-1"></i>
                                            {% else %}
                                                <i class="fa-solid fa-envelope me-1"></i>
                                            {% endif %}
                                            {{ radio.choice_label }}
                                        </label>
                                    {% endfor %}
                                </div>
                            </div>

                            <button type="submit" class="btn btn-primary w-100 py-2 mt-3">{% trans "Login" %}</button>
                        </form>
                        <div class="text-center mt-3">
                            <p>{% trans "Don't have an account?" %} <a href="{% url 'register' %}">{% trans "Register" %}</a></p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
{% endblock %}