<?php
declare(strict_types=1);

/** @var array{ok:?string,err:?string} $flash */
/** @var array{min_impressions:int,clicks_drop_pct:float,impr_drop_pct:float,position_worsen:float} $cfg */

$pageTitle = __('settings.decay.page_title');
$pageHeading = __('settings.decay.heading');
$activeNav = 'settings';
$hideHero = true;
$csrf = \SeoScope\Auth\AdminCsrf::token();

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

    <form method="post" action="<?= seoscope_h(seoscope_url('/settings/decay')) ?>">
        <input type="hidden" name="_csrf" value="<?= seoscope_h($csrf) ?>">
        <div class="row g-3">
            <div class="col-12 col-lg-3">
                <label class="form-label"><?= seoscope_h(__('settings.decay.min_impressions')) ?></label>
                <input class="form-control" type="number" name="min_impressions" min="0" step="1" value="<?= (int) ($cfg['min_impressions'] ?? 0) ?>">
            </div>
            <div class="col-12 col-lg-3">
                <label class="form-label"><?= seoscope_h(__('settings.decay.clicks_drop_pct')) ?></label>
                <input class="form-control" type="number" name="clicks_drop_pct" min="0" max="100" step="1" value="<?= (int) round(((float) ($cfg['clicks_drop_pct'] ?? 0)) * 100) ?>">
                <div class="text-muted small mt-2"><?= seoscope_h(__('settings.decay.pct_help')) ?></div>
            </div>
            <div class="col-12 col-lg-3">
                <label class="form-label"><?= seoscope_h(__('settings.decay.impr_drop_pct')) ?></label>
                <input class="form-control" type="number" name="impr_drop_pct" min="0" max="100" step="1" value="<?= (int) round(((float) ($cfg['impr_drop_pct'] ?? 0)) * 100) ?>">
                <div class="text-muted small mt-2"><?= seoscope_h(__('settings.decay.pct_help')) ?></div>
            </div>
            <div class="col-12 col-lg-3">
                <label class="form-label"><?= seoscope_h(__('settings.decay.position_worsen')) ?></label>
                <input class="form-control" type="number" name="position_worsen" min="0" step="0.1" value="<?= seoscope_h((string) ($cfg['position_worsen'] ?? 0)) ?>">
            </div>
        </div>

        <div class="mt-3">
            <button type="submit" class="btn btn-upgrade"><?= seoscope_h(__('settings.decay.save')) ?></button>
            <a class="btn btn-link" href="<?= seoscope_h(seoscope_url('/settings')) ?>"><?= seoscope_h(__('settings.back')) ?></a>
        </div>
    </form>
</div>
<?php
$content = (string) ob_get_clean();
require __DIR__ . '/layout_admin.php';

