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

<div class="row justify-content-center">
    <div class="col-12 col-xl-10">
        <div class="card shadow-sm border-0" style="border-radius: 12px;">
            <div class="card-header bg-transparent border-0 pt-4 px-4 pb-0 d-flex align-items-center gap-2">
                <i class="bi bi-person-workspace text-primary fs-4"></i>
                <h5 class="fw-bold mb-0 text-dark">Pengaturan Portal Siswa</h5>
            </div>
            
            <div class="card-body p-4">
                <form action="/settings/student-portal/save" method="post">
                    <?= csrf_field() ?>

                    <?php
                    $editableFields = json_decode($setting['student_portal_editable_fields'] ?? '[]', true);
                    if (!is_array($editableFields)) $editableFields = [];
                    ?>

                    <div class="row g-3">
                        <div class="col-12">
                            <label class="form-label fw-bold">Hak Akses Edit Mandiri Siswa</label>
                            <div class="form-text text-muted small mb-3">
                                Centang kolom data berikut agar siswa/ortu diizinkan untuk mengisinya secara mandiri dari portal siswa jika datanya masih kosong/salah.
                            </div>
                            <div class="row">
                                <!-- Identitas & Akademik -->
                                <div class="col-md-4">
                                    <div class="card p-3 border-0 bg-light mb-3" style="border-radius: 8px; min-height: 480px;">
                                        <h6 class="fw-semibold text-primary mb-3"><i class="bi bi-person-badge me-2"></i>Identitas & Akademik</h6>
                                        <div class="form-check mb-2">
                                            <input class="form-check-input" type="checkbox" name="portal_fields[]" value="gender" id="fGender" <?= in_array('gender', $editableFields) ? 'checked' : '' ?>>
                                            <label class="form-check-label text-dark" for="fGender">Jenis Kelamin</label>
                                        </div>
                                        <div class="form-check mb-2">
                                            <input class="form-check-input" type="checkbox" name="portal_fields[]" value="religion" id="fReligion" <?= in_array('religion', $editableFields) ? 'checked' : '' ?>>
                                            <label class="form-check-label text-dark" for="fReligion">Agama</label>
                                        </div>
                                        <div class="form-check mb-2">
                                            <input class="form-check-input" type="checkbox" name="portal_fields[]" value="kip_no" id="fKip" <?= in_array('kip_no', $editableFields) ? 'checked' : '' ?>>
                                            <label class="form-check-label text-dark" for="fKip">No. KIP</label>
                                        </div>
                                        <div class="form-check mb-2">
                                            <input class="form-check-input" type="checkbox" name="portal_fields[]" value="graduation_certificate_no" id="fGrad" <?= in_array('graduation_certificate_no', $editableFields) ? 'checked' : '' ?>>
                                            <label class="form-check-label text-dark" for="fGrad">No. Seri Ijazah</label>
                                        </div>
                                        <div class="form-check mb-2">
                                            <input class="form-check-input" type="checkbox" name="portal_fields[]" value="origin_school" id="fOrigin" <?= in_array('origin_school', $editableFields) ? 'checked' : '' ?>>
                                            <label class="form-check-label text-dark" for="fOrigin">Asal Sekolah</label>
                                        </div>
                                        <div class="form-check mb-2">
                                            <input class="form-check-input" type="checkbox" name="portal_fields[]" value="entry_year" id="fEntryYear" <?= in_array('entry_year', $editableFields) ? 'checked' : '' ?>>
                                            <label class="form-check-label text-dark" for="fEntryYear">Tahun Masuk</label>
                                        </div>
                                        <div class="form-check mb-2">
                                            <input class="form-check-input" type="checkbox" name="portal_fields[]" value="entry_date" id="fEntryDate" <?= in_array('entry_date', $editableFields) ? 'checked' : '' ?>>
                                            <label class="form-check-label text-dark" for="fEntryDate">Tanggal Masuk</label>
                                        </div>
                                    </div>
                                </div>

                                <!-- Alamat & Kontak -->
                                <div class="col-md-4">
                                    <div class="card p-3 border-0 bg-light mb-3" style="border-radius: 8px; min-height: 480px;">
                                        <h6 class="fw-semibold text-primary mb-3"><i class="bi bi-geo-alt me-2"></i>Alamat & Kontak</h6>
                                        <div class="form-check mb-2">
                                            <input class="form-check-input" type="checkbox" name="portal_fields[]" value="phone" id="fPhone" <?= in_array('phone', $editableFields) ? 'checked' : '' ?>>
                                            <label class="form-check-label text-dark" for="fPhone">No. HP Siswa/Wali</label>
                                        </div>
                                        <div class="form-check mb-2">
                                            <input class="form-check-input" type="checkbox" name="portal_fields[]" value="address" id="fAddress" <?= in_array('address', $editableFields) ? 'checked' : '' ?>>
                                            <label class="form-check-label text-dark" for="fAddress">Alamat (Jalan/Dusun)</label>
                                        </div>
                                        <div class="form-check mb-2">
                                            <input class="form-check-input" type="checkbox" name="portal_fields[]" value="rt" id="fRt" <?= in_array('rt', $editableFields) ? 'checked' : '' ?>>
                                            <label class="form-check-label text-dark" for="fRt">RT</label>
                                        </div>
                                        <div class="form-check mb-2">
                                            <input class="form-check-input" type="checkbox" name="portal_fields[]" value="rw" id="fRw" <?= in_array('rw', $editableFields) ? 'checked' : '' ?>>
                                            <label class="form-check-label text-dark" for="fRw">RW</label>
                                        </div>
                                        <div class="form-check mb-2">
                                            <input class="form-check-input" type="checkbox" name="portal_fields[]" value="village" id="fVillage" <?= in_array('village', $editableFields) ? 'checked' : '' ?>>
                                            <label class="form-check-label text-dark" for="fVillage">Desa/Kelurahan</label>
                                        </div>
                                        <div class="form-check mb-2">
                                            <input class="form-check-input" type="checkbox" name="portal_fields[]" value="district" id="fDistrict" <?= in_array('district', $editableFields) ? 'checked' : '' ?>>
                                            <label class="form-check-label text-dark" for="fDistrict">Kecamatan</label>
                                        </div>
                                        <div class="form-check mb-2">
                                            <input class="form-check-input" type="checkbox" name="portal_fields[]" value="city" id="fCity" <?= in_array('city', $editableFields) ? 'checked' : '' ?>>
                                            <label class="form-check-label text-dark" for="fCity">Kabupaten/Kota</label>
                                        </div>
                                        <div class="form-check mb-2">
                                            <input class="form-check-input" type="checkbox" name="portal_fields[]" value="province" id="fProvince" <?= in_array('province', $editableFields) ? 'checked' : '' ?>>
                                            <label class="form-check-label text-dark" for="fProvince">Provinsi</label>
                                        </div>
                                        <div class="form-check mb-2">
                                            <input class="form-check-input" type="checkbox" name="portal_fields[]" value="postal_code" id="fPostalCode" <?= in_array('postal_code', $editableFields) ? 'checked' : '' ?>>
                                            <label class="form-check-label text-dark" for="fPostalCode">Kode Pos</label>
                                        </div>
                                    </div>
                                </div>

                                <!-- Orang Tua / Keluarga -->
                                <div class="col-md-4">
                                    <div class="card p-3 border-0 bg-light mb-3" style="border-radius: 8px; min-height: 480px;">
                                        <h6 class="fw-semibold text-primary mb-3"><i class="bi bi-people me-2"></i>Keluarga / Orang Tua</h6>
                                        <div class="form-check mb-2">
                                            <input class="form-check-input" type="checkbox" name="portal_fields[]" value="family_card_no" id="fKk" <?= in_array('family_card_no', $editableFields) ? 'checked' : '' ?>>
                                            <label class="form-check-label text-dark" for="fKk">No. Kartu Keluarga (KK)</label>
                                        </div>
                                        <div class="form-check mb-2">
                                            <input class="form-check-input" type="checkbox" name="portal_fields[]" value="family_head_name" id="fKkHead" <?= in_array('family_head_name', $editableFields) ? 'checked' : '' ?>>
                                            <label class="form-check-label text-dark" for="fKkHead">Nama Kepala Keluarga</label>
                                        </div>
                                        <div class="form-check mb-2">
                                            <input class="form-check-input" type="checkbox" name="portal_fields[]" value="father_name" id="fFatherName" <?= in_array('father_name', $editableFields) ? 'checked' : '' ?>>
                                            <label class="form-check-label text-dark" for="fFatherName">Nama Ayah</label>
                                        </div>
                                        <div class="form-check mb-2">
                                            <input class="form-check-input" type="checkbox" name="portal_fields[]" value="father_nik" id="fFatherNik" <?= in_array('father_nik', $editableFields) ? 'checked' : '' ?>>
                                            <label class="form-check-label text-dark" for="fFatherNik">NIK Ayah</label>
                                        </div>
                                        <div class="form-check mb-2">
                                            <input class="form-check-input" type="checkbox" name="portal_fields[]" value="father_birth_place" id="fFatherBirthPlace" <?= in_array('father_birth_place', $editableFields) ? 'checked' : '' ?>>
                                            <label class="form-check-label text-dark" for="fFatherBirthPlace">Tempat Lahir Ayah</label>
                                        </div>
                                        <div class="form-check mb-2">
                                            <input class="form-check-input" type="checkbox" name="portal_fields[]" value="father_birth" id="fFatherBirth" <?= in_array('father_birth', $editableFields) ? 'checked' : '' ?>>
                                            <label class="form-check-label text-dark" for="fFatherBirth">Tahun Lahir Ayah</label>
                                        </div>
                                        <div class="form-check mb-2">
                                            <input class="form-check-input" type="checkbox" name="portal_fields[]" value="father_edu" id="fFatherEdu" <?= in_array('father_edu', $editableFields) ? 'checked' : '' ?>>
                                            <label class="form-check-label text-dark" for="fFatherEdu">Pendidikan Ayah</label>
                                        </div>
                                        <div class="form-check mb-2">
                                            <input class="form-check-input" type="checkbox" name="portal_fields[]" value="father_job" id="fFatherJob" <?= in_array('father_job', $editableFields) ? 'checked' : '' ?>>
                                            <label class="form-check-label text-dark" for="fFatherJob">Pekerjaan Ayah</label>
                                        </div>
                                        <div class="form-check mb-2">
                                            <input class="form-check-input" type="checkbox" name="portal_fields[]" value="father_phone" id="fFatherPhone" <?= in_array('father_phone', $editableFields) ? 'checked' : '' ?>>
                                            <label class="form-check-label text-dark" for="fFatherPhone">No. HP Ayah</label>
                                        </div>
                                        <div class="form-check mb-2">
                                            <input class="form-check-input" type="checkbox" name="portal_fields[]" value="mother_name" id="fMotherName" <?= in_array('mother_name', $editableFields) ? 'checked' : '' ?>>
                                            <label class="form-check-label text-dark" for="fMotherName">Nama Ibu</label>
                                        </div>
                                        <div class="form-check mb-2">
                                            <input class="form-check-input" type="checkbox" name="portal_fields[]" value="mother_nik" id="fMotherNik" <?= in_array('mother_nik', $editableFields) ? 'checked' : '' ?>>
                                            <label class="form-check-label text-dark" for="fMotherNik">NIK Ibu</label>
                                        </div>
                                        <div class="form-check mb-2">
                                            <input class="form-check-input" type="checkbox" name="portal_fields[]" value="mother_birth_place" id="fMotherBirthPlace" <?= in_array('mother_birth_place', $editableFields) ? 'checked' : '' ?>>
                                            <label class="form-check-label text-dark" for="fMotherBirthPlace">Tempat Lahir Ibu</label>
                                        </div>
                                        <div class="form-check mb-2">
                                            <input class="form-check-input" type="checkbox" name="portal_fields[]" value="mother_birth" id="fMotherBirth" <?= in_array('mother_birth', $editableFields) ? 'checked' : '' ?>>
                                            <label class="form-check-label text-dark" for="fMotherBirth">Tahun Lahir Ibu</label>
                                        </div>
                                        <div class="form-check mb-2">
                                            <input class="form-check-input" type="checkbox" name="portal_fields[]" value="mother_edu" id="fMotherEdu" <?= in_array('mother_edu', $editableFields) ? 'checked' : '' ?>>
                                            <label class="form-check-label text-dark" for="fMotherEdu">Pendidikan Ibu</label>
                                        </div>
                                        <div class="form-check mb-2">
                                            <input class="form-check-input" type="checkbox" name="portal_fields[]" value="mother_job" id="fMotherJob" <?= in_array('mother_job', $editableFields) ? 'checked' : '' ?>>
                                            <label class="form-check-label text-dark" for="fMotherJob">Pekerjaan Ibu</label>
                                        </div>
                                        <div class="form-check mb-2">
                                            <input class="form-check-input" type="checkbox" name="portal_fields[]" value="mother_phone" id="fMotherPhone" <?= in_array('mother_phone', $editableFields) ? 'checked' : '' ?>>
                                            <label class="form-check-label text-dark" for="fMotherPhone">No. HP Ibu</label>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="col-md-12 mt-3">
                            <label class="form-label fw-bold">Pesan Pengumuman Portal Siswa</label>
                            <textarea name="student_portal_announcement" class="form-control" rows="6"
                                 placeholder="Tulis pesan pengumuman/informasi yang akan muncul di dashboard siswa..."><?= esc($setting['student_portal_announcement'] ?? '') ?></textarea>
                            <div class="form-text text-muted small">
                                 Pesan ini akan tampil di bagian atas dashboard siswa saat mereka masuk ke portal.
                            </div>
                        </div>
                    </div>

                    <!-- Submit -->
                    <div class="d-flex justify-content-end mt-4 pt-3 border-top">
                        <button type="submit" class="btn btn-primary px-4 rounded-pill">
                            <i class="bi bi-save me-2"></i>Simpan Pengaturan
                        </button>
                    </div>

                </form>
            </div>
        </div>
    </div>
</div>

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