<?php
/** @var \BotGuard\Core\View $this @var \BotGuard\Core\Csrf $csrf @var array $data */
$this->layout('install.layout');
$row = static fn (string $label, string $value): string =>
    '<div class="d-flex justify-content-between border-bottom py-2"><span class="text-secondary">' . e($label) . '</span><span class="fw-semibold">' . e($value) . '</span></div>';
?>
<h2 class="h4 mb-1">Ready to Install</h2>
<p class="text-secondary small mb-4">Review your settings. Clicking install will write configuration, build the
    database schema and create your admin account.</p>

<div class="mb-4">
    <?= $row('Site name', $data['app_name'] ?? '—') ?>
    <?= $row('Base URL', $data['app_url'] ?? '—') ?>
    <?= $row('Timezone', $data['app_timezone'] ?? 'UTC') ?>
    <?= $row('Challenge', ucfirst($data['captcha_provider'] ?? 'puzzle')) ?>
    <?= $row('Database', ($data['db_username'] ?? '') . '@' . ($data['db_host'] ?? '') . ':' . ($data['db_port'] ?? '') . '/' . ($data['db_database'] ?? '')) ?>
    <?= $row('Administrator', ($data['admin_name'] ?? '') . ' <' . ($data['admin_email'] ?? '') . '>') ?>
    <?= $row('License mode', ucfirst($data['license_mode'] ?? 'offline')) ?>
</div>

<form method="post" action="/install/install">
    <?= $csrf->field() ?>
    <div class="d-flex justify-content-between">
        <a href="/install/website" class="btn btn-outline-secondary">Back</a>
        <button class="btn btn-success" type="submit" id="installBtn">
            <i class="bi bi-download"></i> Install BotGuard
        </button>
    </div>
</form>
<script>
    document.querySelector('form').addEventListener('submit', function () {
        var b = document.getElementById('installBtn');
        b.disabled = true;
        b.innerHTML = '<span class="spinner-border spinner-border-sm"></span> Installing…';
    });
</script>
