<?php
declare(strict_types=1);

/** @var \SeoScope\Licensing\LicenseState $state */
/** @var array{ok:?string,err:?string} $flash */

require_once __DIR__ . '/http_helpers.php';
$csrf = \SeoScope\Auth\AdminCsrf::token();
$st = isset($state) ? $state : new \SeoScope\Licensing\LicenseState('unlicensed', null, null, null, null);
$flash = is_array($flash ?? null) ? $flash : ['ok' => null, 'err' => null];
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= seoscope_h(__('license.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" style="max-width: 760px;">
            <div class="row g-0">
                <div class="col-12">
                    <div class="login-right" style="min-height: auto;">
                        <div class="login-card">
                            <h2 class="fw-800"><?= seoscope_h(__('license.heading')) ?></h2>
                            <p class="subtitle"><?= seoscope_h(__('license.subtitle')) ?></p>

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

                            <form method="post" action="<?= seoscope_h(seoscope_url('/license')) ?>">
                                <input type="hidden" name="_csrf" value="<?= seoscope_h($csrf) ?>">

                                <div class="mb-3">
                                    <label class="form-label" for="ss-pc"><?= seoscope_h(__('license.purchase_code_label')) ?></label>
                                    <input id="ss-pc" name="purchase_code" class="form-control" required placeholder="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" autocomplete="off">
                                </div>
                                <button type="submit" class="btn-login">
                                    <?= seoscope_h(__('license.activate_btn')) ?>
                                </button>
                            </form>

                            <div class="text-muted small mt-3">
                                <?= seoscope_h(__('license.hint')) ?>
                            </div>

                            <?php if ($st->status !== 'unlicensed'): ?>
                                <div class="mini-stats mt-4">
                                    <div class="mini-stat">
                                        <div class="value"><?= seoscope_h($st->status) ?></div>
                                        <div class="label"><?= seoscope_h(__('license.status')) ?></div>
                                    </div>
                                    <div class="mini-stat">
                                        <div class="value"><?= seoscope_h($st->lastOkAt ? date('Y-m-d', $st->lastOkAt) : '-') ?></div>
                                        <div class="label"><?= seoscope_h(__('license.last_check')) ?></div>
                                    </div>
                                </div>
                            <?php endif; ?>

                            <p class="helper-text mt-4 mb-0">
                                <a href="<?= seoscope_h(seoscope_url('/login')) ?>"><?= seoscope_h(__('license.back_to_login')) ?></a>
                            </p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="<?= seoscope_h(seoscope_url('/assets/vendor/bootstrap/bootstrap.bundle.min.js')) ?>"></script>
</body>
</html>

