<?php
declare(strict_types=1);
/** @var array{ok:?string,err:?string} $flash */
/** @var bool $invalid */
/** @var string $token */

require_once __DIR__ . '/http_helpers.php';
$csrf = \SeoScope\Auth\AdminCsrf::token();
$invalid = (bool) ($invalid ?? false);
$token = (string) ($token ?? '');
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= seoscope_h(__('auth.reset_title')) ?> — <?= seoscope_h(__('app.name')) ?></title>
    <link rel="stylesheet" href="<?= seoscope_h(seoscope_url('/assets/fonts/inter/inter.css')) ?>">
    <link rel="stylesheet" href="<?= seoscope_h(seoscope_url('/assets/vendor/bootstrap/bootstrap.min.css')) ?>">
    <link rel="stylesheet" href="<?= seoscope_h(seoscope_url('/assets/vendor/fontawesome/css/all.min.css')) ?>">
    <link rel="stylesheet" href="<?= seoscope_h(seoscope_url('/assets/admin-template/css/admin-template.css')) ?>">
</head>
<body class="login-page">
    <div class="login-shell">
        <div class="login-wrapper">
            <div class="row g-0">
                <div class="col-lg-5">
                    <div class="login-left">
                        <div>
                            <div class="brand mb-5">
                                <span class="brand-icon"><i class="fa-solid fa-wave-square"></i></span>
                                <span><?= seoscope_h(__('app.name')) ?></span>
                            </div>
                            <div class="left-copy">
                                <h1 class="fw-800"><?= seoscope_h(__('auth.reset_hero')) ?></h1>
                                <p class="mb-0"><?= seoscope_h(__('auth.reset_subtitle')) ?></p>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="col-lg-7">
                    <div class="login-right">
                        <div class="login-card">
                            <h2 class="fw-800"><?= seoscope_h(__('auth.reset_title')) ?></h2>
                            <p class="subtitle"><?= seoscope_h(__('auth.reset_help')) ?></p>

                            <?php if (!empty($flash['ok'])): ?>
                                <div class="alert alert-success mb-4"><?= seoscope_h($flash['ok']) ?></div>
                            <?php endif; ?>
                            <?php if (!empty($flash['err'])): ?>
                                <div class="alert alert-danger mb-4"><?= seoscope_h($flash['err']) ?></div>
                            <?php endif; ?>

                            <?php if ($invalid): ?>
                                <div class="alert alert-danger mb-4"><?= seoscope_h(__('auth.reset_invalid')) ?></div>
                                <p class="helper-text"><a href="<?= seoscope_h(seoscope_url('/forgot-password')) ?>"><?= seoscope_h(__('auth.reset_request_new')) ?></a></p>
                            <?php else: ?>
                                <form method="post" action="<?= seoscope_h(seoscope_url('/reset-password')) ?>">
                                    <input type="hidden" name="_csrf" value="<?= seoscope_h($csrf) ?>">
                                    <input type="hidden" name="t" value="<?= seoscope_h($token) ?>">

                                    <div class="mb-4">
                                        <label for="password" class="form-label"><?= seoscope_h(__('auth.new_password')) ?></label>
                                        <input type="password" class="form-control" id="password" name="password" placeholder="••••••••••••" required autocomplete="new-password" minlength="12">
                                        <div class="text-muted small mt-2"><?= seoscope_h(__('auth.password_hint')) ?></div>
                                    </div>

                                    <div class="mb-4">
                                        <label for="password_confirm" class="form-label"><?= seoscope_h(__('auth.new_password_confirm')) ?></label>
                                        <input type="password" class="form-control" id="password_confirm" name="password_confirm" placeholder="••••••••••••" required autocomplete="new-password" minlength="12">
                                    </div>

                                    <button type="submit" class="btn-login"><?= seoscope_h(__('auth.reset_submit')) ?></button>
                                </form>

                                <p class="helper-text mt-3">
                                    <a href="<?= seoscope_h(seoscope_url('/login')) ?>"><?= seoscope_h(__('auth.back_to_login')) ?></a>
                                </p>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="<?= seoscope_h(seoscope_url('/assets/vendor/bootstrap/bootstrap.bundle.min.js')) ?>"></script>
</body>
</html>

