<?= $this->extend('install/_layout') ?>
<?php $currentStep = 5; ?>

<?= $this->section('content') ?>
<h5 class="mb-3">Step 5 — Super Admin Account</h5>

<form id="adminForm">
    <div class="row g-3">
        <div class="col-12">
            <label class="form-label">Full Name</label>
            <input type="text" class="form-control" name="name" required>
        </div>
        <div class="col-12">
            <label class="form-label">Email</label>
            <input type="email" class="form-control" name="email" required>
        </div>
        <div class="col-6">
            <label class="form-label">Password</label>
            <input type="password" class="form-control" name="password" minlength="10" required>
            <div class="form-text">Minimum 10 characters.</div>
        </div>
        <div class="col-6">
            <label class="form-label">Confirm Password</label>
            <input type="password" class="form-control" name="password_confirmation" minlength="10" required>
        </div>
    </div>

    <div class="d-flex justify-content-between mt-4">
        <a href="<?= base_url('install/step/4') ?>" class="btn btn-outline-secondary">← Back</a>
        <button type="submit" class="btn btn-primary">Next: SMTP Configuration →</button>
    </div>
</form>
<?= $this->endSection() ?>

<?= $this->section('scripts') ?>
<script>
document.getElementById('adminForm').addEventListener('submit', async (e) => {
    e.preventDefault();
    const res = await fetch('<?= base_url('install/step/5') ?>', {
        method: 'POST',
        headers: {'Content-Type': 'application/x-www-form-urlencoded'},
        body: new URLSearchParams(new FormData(e.target))
    });
    const json = await res.json();
    if (json.success) { window.location.href = json.data.next; }
    else { alert(json.errors.map(e => e.message).join('\n')); }
});
</script>
<?= $this->endSection() ?>
