<?= $this->extend('layouts/main') ?>
<?= $this->section('content') ?>

<div class="mb-3">
    <h5 class="mb-0 fw-bold">Pengaturan Aplikasi</h5>
</div>

<div class="row">
    <div class="col-md-6">
        <div class="card">
            <div class="card-header">Umum</div>
            <div class="card-body">
                <div class="mb-3">
                    <label class="form-label fw-semibold">Nama Aplikasi</label>
                    <input type="text" id="appName" class="form-control" value="<?= esc($app_name) ?>" placeholder="Nama aplikasi">
                    <div class="form-text">Nama ini ditampilkan di sidebar dan judul halaman.</div>
                </div>
                <button class="btn btn-primary" onclick="saveSettings()">
                    <i class="bi bi-save me-1"></i> Simpan Pengaturan
                </button>
            </div>
        </div>
    </div>
</div>

<?= $this->endSection() ?>
<?= $this->section('scripts') ?>
<script>
function saveSettings() {
    const appName = document.getElementById('appName').value.trim();
    if (!appName) { Swal.fire('Perhatian', 'Nama aplikasi tidak boleh kosong.', 'warning'); return; }

    postData('settings/save', {app_name: appName}, function(r) {
        Swal.fire({icon:'success', title:'Berhasil', text:'Pengaturan disimpan.', timer:1500, showConfirmButton:false});
        // Update sidebar app name
        const el = document.querySelector('#sidebar .app-name');
        if (el) el.textContent = r.app_name;
    });
}
</script>
<?= $this->endSection() ?>
