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

{% block title %}Set New Password - IHICL Investment{% endblock %}

{% block content %}
    <!-- Header Start -->
    <div class="container-fluid bg-breadcrumb">
        <div class="bg-breadcrumb-single"></div>
        <div class="container text-center py-5" style="max-width: 900px;">
            <h4 class="text-white display-4 mb-4 wow fadeInDown" data-wow-delay="0.1s">Set New Password</h4>
            <ol class="breadcrumb justify-content-center mb-0 wow fadeInDown" data-wow-delay="0.3s">
                <li class="breadcrumb-item"><a href="{% url 'home' %}">Home</a></li>
                <li class="breadcrumb-item"><a href="{% url 'login' %}">Login</a></li>
                <li class="breadcrumb-item active text-primary">New Password</li>
            </ol>    
        </div>
    </div>
    <!-- Header End -->

    <!-- Password Reset Confirm Section Start -->
    <div class="container-fluid py-5">
        <div class="container">
            <div class="row justify-content-center">
                <div class="col-lg-6">
                    <div class="card border-0 shadow-sm">
                        <div class="card-body p-5">
                            <h3 class="text-center mb-4">Set New Password</h3>
                            
                            {% if validlink %}
                                <p class="text-center mb-4">Please enter your new password twice so we can verify you typed it in correctly.</p>
                                
                                <form method="post">
                                    {% csrf_token %}
                                    
                                    <div class="mb-3 password-input-group">
                                        <label for="id_new_password1" class="form-label">New Password</label>
                                        <input type="password" class="form-control {% if form.new_password1.errors %}is-invalid{% endif %}" 
                                               id="id_new_password1" name="new_password1" placeholder="Enter new password" required>
                                        <span class="password-toggle" onclick="togglePassword('id_new_password1')">
                                            <i class="far fa-eye"></i>
                                        </span>
                                        {% if form.new_password1.errors %}
                                            <div class="invalid-feedback">
                                                {{ form.new_password1.errors.0 }}
                                            </div>
                                        {% endif %}
                                        <div class="form-text">Must be at least 8 characters with a number and symbol</div>
                                    </div>
                                    
                                    <div class="mb-4 password-input-group">
                                        <label for="id_new_password2" class="form-label">Confirm New Password</label>
                                        <input type="password" class="form-control {% if form.new_password2.errors %}is-invalid{% endif %}" 
                                               id="id_new_password2" name="new_password2" placeholder="Confirm new password" required>
                                        <span class="password-toggle" onclick="togglePassword('id_new_password2')">
                                            <i class="far fa-eye"></i>
                                        </span>
                                        {% if form.new_password2.errors %}
                                            <div class="invalid-feedback">
                                                {{ form.new_password2.errors.0 }}
                                            </div>
                                        {% endif %}
                                    </div>
                                    
                                    <button type="submit" class="btn btn-primary w-100 py-2">Change Password</button>
                                </form>
                            {% else %}
                                <div class="alert alert-danger text-center">
                                    <h4 class="alert-heading">Invalid Link</h4>
                                    <p>The password reset link was invalid, possibly because it has already been used. Please request a new password reset.</p>
                                </div>
                                <div class="text-center">
                                    <a href="{% url 'password_reset' %}" class="btn btn-primary">Request New Reset Link</a>
                                </div>
                            {% endif %}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- Password Reset Confirm Section End -->

    <style>
        .password-input-group {
            position: relative;
        }
        
        .password-toggle {
            cursor: pointer;
            position: absolute;
            right: 15px;
            top: 40px;
            color: #6c757d;
        }
    </style>

    <script>
        function togglePassword(inputId) {
            const passwordInput = document.getElementById(inputId);
            const toggleIcon = passwordInput.parentNode.querySelector('.password-toggle i');
            
            if (passwordInput.type === 'password') {
                passwordInput.type = 'text';
                toggleIcon.classList.remove('fa-eye');
                toggleIcon.classList.add('fa-eye-slash');
            } else {
                passwordInput.type = 'password';
                toggleIcon.classList.remove('fa-eye-slash');
                toggleIcon.classList.add('fa-eye');
            }
        }
    </script>
{% endblock %}