<?php
require_once __DIR__ . '/app/helpers/csrf.php';
require_once __DIR__ . '/app/helpers/auth.php';
initSessionConfig();
$csrfToken = generateCsrfToken();
?>
<!DOCTYPE html>
<html>
<head>
    <title>Forgot Password</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="bg-light d-flex align-items-center justify-content-center" style="height:100vh;">

<div class="card p-4 shadow" style="width:380px;">
    <h4 class="mb-3 text-center">Forgot Password</h4>

    <p class="text-muted small mb-3">
        Enter your email address and we'll send you a password reset link.
    </p>

    <input type="email" id="email" class="form-control mb-3" placeholder="Email">
    <button id="sendReset" class="btn btn-primary w-100">Send Reset Link</button>

    <div class="text-center mt-3">
        <a href="login.php">Back to Login</a>
    </div>
</div>

<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script>
var csrfToken = <?= json_encode($csrfToken) ?>;
$('#sendReset').click(function () {
$.post('password_reset_handler.php?action=forgot', {
        email: $('#email').val(),
        _csrf_token: csrfToken
    }, function (res) {
        alert(res.message || 'Reset email sent.');
    }, 'json').fail(function () {
        alert('Unable to process request.');
    });
});
</script>

</body>
</html>
