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

<div class="row justify-content-center">
    <div class="col-12 col-md-6">
        <div class="card shadow-sm">
            <div class="card-header">
                <h5 class="mb-0"><i class="bi bi-gear me-2 text-primary"></i>Pengaturan QR Scan</h5>
                <small class="text-muted">Atur jam operasional dan status fitur absensi QR</small>
            </div>
            <div class="card-body">
                <?php if (session()->getFlashdata('success')): ?>
                <div class="alert alert-success">
                    <i class="bi bi-check-circle me-2"></i><?= session()->getFlashdata('success') ?>
                </div>
                <?php endif; ?>

                <form action="/attendance/qr-settings" method="post">
                    <?= csrf_field() ?>

                    <div class="mb-3">
                        <label class="form-label fw-semibold">Jam Mulai Scan</label>
                        <input type="time" name="qr_scan_start_time" class="form-control"
                               value="<?= esc($settings['qr_scan_start_time'] ?? '06:00') ?>">
                        <div class="form-text">Scan QR akan diterima mulai jam ini.</div>
                    </div>

                    <div class="mb-3">
                        <label class="form-label fw-semibold">Jam Selesai Scan</label>
                        <input type="time" name="qr_scan_end_time" class="form-control"
                               value="<?= esc($settings['qr_scan_end_time'] ?? '08:00') ?>">
                        <div class="form-text">Scan QR di atas jam ini akan ditolak.</div>
                    </div>

                    <div class="mb-4">
                        <label class="form-label fw-semibold">Status Fitur</label>
                        <select name="qr_scan_active" class="form-select">
                            <option value="1" <?= ($settings['qr_scan_active'] ?? '1') == '1' ? 'selected' : '' ?>>Aktif</option>
                            <option value="0" <?= ($settings['qr_scan_active'] ?? '1') == '0' ? 'selected' : '' ?>>Nonaktif</option>
                        </select>
                        <div class="form-text">Jika dinonaktifkan, semua scan QR akan ditolak.</div>
                    </div>

                    <div class="d-flex gap-2">
                        <button type="submit" class="btn btn-primary">
                            <i class="bi bi-save me-1"></i>Simpan Pengaturan
                        </button>
                        <a href="/attendance/qr-scan" class="btn btn-outline-success">
                            <i class="bi bi-qr-code-scan me-1"></i>Buka Scanner
                        </a>
                        <a href="/attendance/qr-report" class="btn btn-outline-secondary">
                            <i class="bi bi-list-ul me-1"></i>Rekap Hari Ini
                        </a>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<?= $this->endSection() ?>
