<?php
require __DIR__ . '/includes/functions.php';
$currentPage = 'account';
$pageTitle = 'Forgot Password | Furnify';
$message = '';
$debugLink = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if (!verify_csrf_token((string) (isset($_POST['csrf_token']) ? $_POST['csrf_token'] : ''))) {
        $message = 'Security token expired. Please try again.';
    } else {
        $result = customer_generate_password_reset(isset($_POST['email']) ? $_POST['email'] : '');
        $message = 'If the email is registered, a password reset link has been sent.';
        if ($result['customer'] && customer_show_debug_verification_link() && $result['token'] !== '') {
            $debugLink = site_root_url('reset-password.php?c=' . urlencode((string) $result['customer']['id']) . '&t=' . urlencode($result['token']));
            start_secure_session();
            $_SESSION['last_reset_link'] = $debugLink;
        }
    }
}
require __DIR__ . '/includes/header.php';
?>
<section class="page-section"><div class="container narrow"><div class="premium-panel p-4 p-lg-5"><p class="eyebrow">Customer account</p><h1>Forgot password</h1><p class="lead">Enter your email and we will send a reset link if the account exists.</p><?php if ($message): ?><div class="alert alert-info"><?= e($message) ?></div><?php endif; ?><?php if ($debugLink): ?><div class="alert alert-warning"><strong>Testing reset link:</strong> <a href="<?= e($debugLink) ?>"><?= e($debugLink) ?></a></div><?php endif; ?><form method="post" class="row g-3"><input type="hidden" name="csrf_token" value="<?= e(csrf_token()) ?>"><div class="col-12"><label class="form-label">Email</label><input class="form-control" type="email" name="email" required></div><div class="col-12"><button class="btn btn-primary w-100" type="submit">Send reset link</button></div></form><p class="mt-4 mb-0 text-center"><a href="login.php">Back to login</a></p></div></div></section>
<?php require __DIR__ . '/includes/footer.php'; ?>
