{% extends "accounts/login.html" %}

{% block content %}
<div class="container-fluid min-vh-100 d-flex align-items-center justify-content-center py-4">
    <div class="auth-wrapper w-100" style="max-width: 500px;">
        <div class="auth-card row g-0">
            <div class="col-12 auth-form-side">
                
                <div class="text-center mb-4">
                    <div class="auth-brand-mark mx-auto mb-3">
                        <i class="fas fa-lock fa-2x text-primary d-block"></i>
                    </div>
                    <h2 class="auth-title mb-2">Create New Password</h2>
                    
                    {% if validlink %}
                        <p class="auth-subtitle mb-0">
                            Please enter your new password below.
                        </p>
                    {% else %}
                        <p class="auth-subtitle text-danger fw-bold mb-0">
                            Warning: This reset link has expired or is invalid.
                        </p>
                    {% endif %}
                </div>

                {% if validlink %}
                    <form method="post" novalidate>
                        {% csrf_token %}
                        
                        {% if form.non_field_errors %}
                            <div class="alert alert-danger mb-3" role="alert">
                                {% for error in form.non_field_errors %}
                                    <div>{{ error }}</div>
                                {% endfor %}
                            </div>
                        {% endif %}

                        {% for field in form %}
                        <div class="mb-3">
                            <label for="{{ field.id_for_label }}" class="auth-input-label mb-1">{{ field.label }}</label>
                            <input
                                type="password"
                                name="{{ field.html_name }}"
                                required
                                id="{{ field.id_for_label }}"
                                class="form-control form-control-auth"
                                placeholder="{{ field.label }}">
                            {% if field.help_text %}
                                <div class="form-text small mt-1">{{ field.help_text }}</div>
                            {% endif %}
                            {% if field.errors %}
                                <div class="invalid-feedback d-block">
                                    {{ field.errors.0 }}
                                </div>
                            {% endif %}
                        </div>
                        {% endfor %}

                        <div class="d-grid mt-4">
                            <button type="submit" class="btn btn-auth-primary">
                                Change Password <i class="fas fa-check-circle ms-2"></i>
                            </button>
                        </div>
                    </form>
                {% else %}
                    <div class="alert alert-danger text-center">
                        <p class="mb-3">The password reset link was invalid, possibly because it has already been used or has expired after 30 minutes.</p>
                        <a href="{% url 'password_reset' %}" class="btn btn-sm btn-outline-danger w-100">Request a new password reset</a>
                    </div>
                    <div class="text-center mt-3">
                        <a href="{% url 'login' %}" class="text-decoration-none small fw-semibold text-muted">
                            <i class="fas fa-arrow-left me-1"></i> Back to login
                        </a>
                    </div>
                {% endif %}

            </div>
        </div>
        
        <div class="text-center mt-3 auth-footer-text text-light">
            &copy; {% now "Y" %} SwiftPOS. Safe & Secure System.
        </div>
    </div>
</div>
{% endblock %}
