<!DOCTYPE html>
<?php /* Variables: $baseUrl, $assetsUrl, $error, $success, $token, $viaLink, $email */ ?>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Reset password · <?= htmlspecialchars(\PpPhp\Core\Brand::name()) ?></title>
    <link href="<?= $assetsUrl ?>/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="<?= $assetsUrl ?>/icons/bootstrap-icons.css" rel="stylesheet">
    <?php include constant('BASE_PATH') . '/core/views/theme-head.php'; ?>
    <?php include __DIR__ . '/partials/auth-card.css.php'; ?>
</head>

<body>
    <main class="auth-wrap">
        <div class="auth-card">
            <div style="display:flex;justify-content:center;margin-bottom:1.1rem"><?= \PpPhp\Core\Brand::lockup(30) ?></div>
            <div class="auth-head">
                <span class="auth-mark"><i class="bi bi-shield-lock-fill"></i></span>
                <h1>Choose a new password</h1>
                <p>
                    <?= $viaLink
                        ? 'Your link checked out — pick a new password below.'
                        : 'Enter the 6-digit code we emailed you, then pick a new password.' ?>
                </p>
            </div>

            <?php if ($success): ?>
                <div class="auth-msg ok"><i class="bi bi-check-circle-fill"></i><span><?= htmlspecialchars($success) ?></span></div>
            <?php endif; ?>
            <?php if ($error): ?>
                <div class="auth-msg err"><i class="bi bi-exclamation-triangle-fill"></i><span><?= htmlspecialchars($error) ?></span></div>
            <?php endif; ?>

            <form method="post" action="<?= $baseUrl ?>/reset-password" novalidate>
                <?php if ($viaLink): ?>
                    <input type="hidden" name="token" value="<?= htmlspecialchars($token) ?>">
                <?php else: ?>
                    <div class="mb-3">
                        <label class="auth-label" for="email">Email address</label>
                        <input class="form-control" id="email" name="email" type="email" required
                            value="<?= htmlspecialchars($email) ?>" placeholder="you@example.com" autocomplete="email">
                    </div>
                    <div class="mb-3">
                        <label class="auth-label" for="otp">6-digit code</label>
                        <input class="form-control auth-otp" id="otp" name="otp" inputmode="numeric" pattern="[0-9]*"
                            maxlength="6" required placeholder="000000" autocomplete="one-time-code">
                        <div class="auth-hint">Check your inbox — the code expires shortly after it's sent.</div>
                    </div>
                <?php endif; ?>

                <div class="mb-3">
                    <label class="auth-label" for="password">New password</label>
                    <input class="form-control" id="password" name="password" type="password" required minlength="8"
                        placeholder="At least 8 characters" autocomplete="new-password">
                </div>
                <div class="mb-1">
                    <label class="auth-label" for="password_confirm">Confirm new password</label>
                    <input class="form-control" id="password_confirm" name="password_confirm" type="password" required
                        minlength="8" placeholder="Type it again" autocomplete="new-password">
                </div>

                <button class="auth-btn mt-3" type="submit"><i class="bi bi-check2-circle me-1"></i> Save new password</button>
            </form>

            <div class="auth-foot">
                <a href="<?= $baseUrl ?>/login"><i class="bi bi-arrow-left me-1"></i> Back to sign in</a>
                <a href="<?= $baseUrl ?>/forgot-password">Send a new code</a>
            </div>
        </div>
    </main>
</body>

</html>
