<?php
declare(strict_types=1);

/** @var array{ok:?string,err:?string} $flash */
/** @var array{id:int,email:string,name:?string,created_at?:string,last_login_at?:string} $user */

$pageTitle = __('account.page_title');
$pageHeading = __('account.heading');
$activeNav = 'settings';
$hideHero = true;

ob_start();
?>
<div class="dashboard-card section-card">
    <div class="section-title mb-2"><?= seoscope_h(__('account.heading')) ?></div>
    <div class="section-subtitle mb-3"><?= seoscope_h(__('account.subtitle')) ?></div>

    <div class="dashboard-card section-card" style="background: rgba(255,255,255,0.70);">
        <form method="post" action="<?= seoscope_h(seoscope_url('/account')) ?>" class="m-0">
            <input type="hidden" name="_csrf" value="<?= seoscope_h(\SeoScope\Auth\AdminCsrf::token()) ?>">
            <div class="row g-3">
                <div class="col-12 col-lg-6">
                    <label class="form-label"><?= seoscope_h(__('account.username_label')) ?></label>
                    <input class="form-control" type="text" name="username" maxlength="255" value="<?= seoscope_h((string) ($user['name'] ?? '')) ?>" placeholder="<?= seoscope_h(__('account.username_placeholder')) ?>">
                    <div class="text-muted small mt-2"><?= seoscope_h(__('account.username_help')) ?></div>
                </div>
                <div class="col-12 col-lg-6">
                    <label class="form-label"><?= seoscope_h(__('account.email_label')) ?></label>
                    <input class="form-control" type="email" name="email" maxlength="255" value="<?= seoscope_h((string) ($user['email'] ?? '')) ?>">
                    <div class="text-muted small mt-2"><?= seoscope_h(__('account.email_help')) ?></div>
                </div>
            </div>

            <div class="mt-3">
                <button type="submit" class="btn btn-upgrade"><?= seoscope_h(__('account.save')) ?></button>
            </div>
        </form>

        <div class="mt-3 d-flex align-items-center justify-content-between flex-wrap gap-2">
            <a class="btn btn-outline-secondary" href="<?= seoscope_h(seoscope_url('/account/password')) ?>">
                <?= seoscope_h(__('account.change_password')) ?>
            </a>
            <form method="post" action="<?= seoscope_h(seoscope_url('/logout')) ?>" class="m-0">
                <input type="hidden" name="_csrf" value="<?= seoscope_h(\SeoScope\Auth\AdminCsrf::token()) ?>">
                <button type="submit" class="btn btn-outline-secondary">
                    <?= seoscope_h(__('account.logout')) ?>
                </button>
            </form>
        </div>
    </div>
</div>
<?php
$content = (string) ob_get_clean();
require __DIR__ . '/layout_admin.php';

