<!-- resources/templates/reset-password.html -->
<!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>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css">
</head>
<body class="bg-gray-100">

<!-- Include the navbar from mainlayout -->
<div th:replace="layouts/mainLayout"></div>
<div class="container mx-auto p-4">

    <h2 class="text-2xl font-semibold mb-4 text-center">Reset Password</h2>

    <form th:action="@{/reset-password}" method="post" class="max-w-md mx-auto bg-white p-8 my-8 rounded-md shadow-md" id="resetPasswordForm">
        <input type="hidden" name="token" th:value="${param.token}" />

        <div class="mb-4">
            <label for="password" class="block text-sm font-medium text-gray-600">New Password:</label>
            <input type="password" id="password" name="password" required
                   class="mt-1 p-2 block w-full border rounded-md focus:ring focus:ring-indigo-200 focus:outline-none">
            <div id="passwordRequirements" class="mt-2 text-sm text-gray-600 hidden">
                Password must be at least 8 characters long, contain at least 1 number, and 1 special character.
            </div>
        </div>

        <button type="submit" class="w-full bg-indigo-500 text-white py-2 px-4 rounded-md hover:bg-indigo-600 focus:outline-none focus:ring focus:ring-indigo-200">
            Reset Password
        </button>
    </form>

    <div th:if="${param.same}" class="text-red-500 text-center">
        <p>Old and New Password Cannot be the Same</p>
    </div>

    <script>
        // Add an event listener to the form to prevent submission if validation fails
        document.getElementById('resetPasswordForm').addEventListener('submit', function (event) {
            const passwordRequirements = document.getElementById('passwordRequirements');
            const passwordInput = document.getElementById('password');

            // Your password validation logic here
            const isValidPassword = validatePassword(passwordInput.value);

            // Show/hide the requirements based on validation result
            passwordRequirements.style.display = isValidPassword ? 'none' : 'block';

            // Prevent form submission if validation fails
            if (!isValidPassword) {
                event.preventDefault();
            }
        });

        // Password validation function
        function validatePassword(password) {
            // Your password validation logic here
            // For example, checking if the password is at least 8 characters long
            return password.length >= 8;
        }
    </script>

</div>
<div th:replace="layouts/footerLayout"></div>
</body>
</html>
