<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Reset Password</title>
    <style>
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
            line-height: 1.6;
            margin: 0;
            padding: 0;
            background-color: #f5f5f5;
            color: #333;
        }
        .container {
            max-width: 600px;
            margin: 2rem auto;
            padding: 2rem;
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }
        h1 {
            color: #2c3e50;
            margin-bottom: 1.5rem;
            text-align: center;
        }
        .form-group {
            margin-bottom: 1.5rem;
        }
        label {
            display: block;
            margin-bottom: 0.5rem;
            font-weight: 500;
        }
        input[type="password"] {
            width: 100%;
            padding: 0.75rem;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 1rem;
            box-sizing: border-box;
        }
        .error {
            color: #e74c3c;
            font-size: 0.875rem;
            margin-top: 0.25rem;
        }
        button {
            background-color: #3498db;
            color: white;
            border: none;
            padding: 0.75rem 1.5rem;
            border-radius: 4px;
            cursor: pointer;
            font-size: 1rem;
            width: 100%;
            transition: background-color 0.2s;
        }
        button:hover {
            background-color: #2980b9;
        }
        .message {
            padding: 1rem;
            border-radius: 4px;
            margin-bottom: 1rem;
        }
        .error-message {
            background-color: #fde8e8;
            color: #c53030;
            border: 1px solid #fbd5d5;
        }
        .success-message {
            background-color: #def7ec;
            color: #03543f;
            border: 1px solid #bcf0da;
        }
        @media (max-width: 640px) {
            .container {
                margin: 1rem;
                padding: 1rem;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>Reset Your Password</h1>
        
        {% if validlink %}
            <form method="post" id="password-reset-form" action="{% url 'rest_password_reset_set_new' %}">
                {% csrf_token %}
                <input type="hidden" name="username" value="{{ form.user.get_username }}">
                
                <div class="form-group">
                    <label for="id_new_password1">New Password</label>
                    <input type="password" name="new_password1" id="id_new_password1" required>
                    {% if form.new_password1.errors %}
                        <div class="error">{{ form.new_password1.errors }}</div>
                    {% endif %}
                </div>
                
                <div class="form-group">
                    <label for="id_new_password2">Confirm New Password</label>
                    <input type="password" name="new_password2" id="id_new_password2" required>
                    {% if form.new_password2.errors %}
                        <div class="error">{{ form.new_password2.errors }}</div>
                    {% endif %}
                </div>
                
                <button type="submit">Change Password</button>
            </form>
        {% else %}
            <div class="message error-message">
                <p>The password reset link was invalid, possibly because it has already been used. Please request a new password reset.</p>
            </div>
        {% endif %}
    </div>

    <script>
        document.querySelector('form').addEventListener('submit', function(e) {
            e.preventDefault();
            const formData = new FormData(this);
            
            fetch(this.action, {
                method: 'POST',
                body: formData,
                headers: {
                    'X-CSRFToken': document.querySelector('[name=csrfmiddlewaretoken]').value
                }
            })
            .then(response => {
                if (response.ok) {
                    window.location.href = "{% url 'jwt_allauth_password_reset_complete' %}";
                } else {
                    throw new Error('Password reset failed');
                }
            })
            .catch(error => {
                console.error('Error:', error);
                alert('Password reset failed. Please try again.');
            });
        });
    </script>
</body>
</html> 