<?= $this->extend('layout/admin') ?>
<?= $this->section('content') ?>

<?php
$base   = base_url('uploads/ppdb/');
$rapors = json_decode($record['rapor_file'] ?? '[]', true);
?>

<style>
.ppdb-card{
    border-radius:14px;
    border:1px solid #e5e9ff;
}
.ppdb-section{
    border-bottom:1px dashed #e0e6ff;
    padding:22px 24px;
}
.ppdb-section:last-child{
    border-bottom:none;
}
.ppdb-title{
    font-weight:800;
    color:#1b2cff;
    margin-bottom:14px;
}
.ppdb-label{
    font-size:12px;
    color:#6c77c7;
}
.ppdb-value{
    font-weight:600;
    font-size:14px;
    color:#1f2a60;
}
.doc-box{
    border:1px dashed #cfd7ff;
    border-radius:12px;
    padding:14px;
    background:#fbfcff;
}
</style>

<div class="card shadow-sm ppdb-card">

    <!-- ================= IDENTITAS SISWA ================= -->
    <div class="ppdb-section">
        <div class="ppdb-title">
            <i class="fas fa-id-card me-2"></i> Identitas Siswa
        </div>

        <div class="row g-3">
            <div class="col-md-4">
                <div class="ppdb-label">Nomor Pendaftaran</div>
                <div class="ppdb-value"><?= $record['reg_no'] ?></div>
            </div>
            <div class="col-md-4">
                <div class="ppdb-label">Nama Lengkap</div>
                <div class="ppdb-value"><?= $record['name'] ?></div>
            </div>
            <div class="col-md-4">
                <div class="ppdb-label">Nama Panggilan</div>
                <div class="ppdb-value"><?= $record['nickname'] ?? '-' ?></div>
            </div>

            <div class="col-md-3">
                <div class="ppdb-label">Jenis Kelamin</div>
                <div class="ppdb-value"><?= $record['gender']=='M'?'Laki-laki':'Perempuan' ?></div>
            </div>
            <div class="col-md-3">
                <div class="ppdb-label">NISN</div>
                <div class="ppdb-value"><?= $record['nisn'] ?></div>
            </div>
            <div class="col-md-3">
                <div class="ppdb-label">NIK</div>
                <div class="ppdb-value"><?= $record['nik'] ?></div>
            </div>
            <div class="col-md-3">
                <div class="ppdb-label">Agama</div>
                <div class="ppdb-value"><?= $record['religion'] ?></div>
            </div>

            <div class="col-md-4">
                <div class="ppdb-label">Tempat Lahir</div>
                <div class="ppdb-value"><?= $record['birth_place'] ?></div>
            </div>
            <div class="col-md-4">
                <div class="ppdb-label">Tanggal Lahir</div>
                <div class="ppdb-value"><?= $record['birth_date'] ?></div>
            </div>
            <div class="col-md-4">
                <div class="ppdb-label">Kewarganegaraan</div>
                <div class="ppdb-value"><?= $record['citizenship'] ?></div>
            </div>
        </div>
    </div>

    <!-- ================= ALAMAT ================= -->
    <div class="ppdb-section">
        <div class="ppdb-title">
            <i class="fas fa-map-marker-alt me-2"></i> Alamat Domisili
        </div>

        <div class="row g-3">
            <div class="col-md-6">
                <div class="ppdb-label">Alamat Lengkap</div>
                <div class="ppdb-value"><?= $record['address_street'] ?></div>
            </div>
            <div class="col-md-2">
                <div class="ppdb-label">RT / RW</div>
                <div class="ppdb-value"><?= $record['rt_rw'] ?></div>
            </div>
            <div class="col-md-2">
                <div class="ppdb-label">Kode Pos</div>
                <div class="ppdb-value"><?= $record['postal_code'] ?></div>
            </div>

            <div class="col-md-3">
                <div class="ppdb-label">Provinsi</div>
                <div class="ppdb-value"><?= $record['province'] ?></div>
            </div>
            <div class="col-md-3">
                <div class="ppdb-label">Kota / Kab</div>
                <div class="ppdb-value"><?= $record['city'] ?></div>
            </div>
            <div class="col-md-3">
                <div class="ppdb-label">Kecamatan</div>
                <div class="ppdb-value"><?= $record['district'] ?></div>
            </div>
            <div class="col-md-3">
                <div class="ppdb-label">Kelurahan</div>
                <div class="ppdb-value"><?= $record['village'] ?></div>
            </div>
        </div>
    </div>

    <!-- ================= ORANG TUA ================= -->
    <div class="ppdb-section">
        <div class="ppdb-title">
            <i class="fas fa-users me-2"></i> Data Orang Tua
        </div>

        <div class="row g-3">
            <div class="col-md-6">
                <div class="ppdb-label">Nama Ayah</div>
                <div class="ppdb-value"><?= $record['father_name'] ?></div>
            </div>
            <div class="col-md-3">
                <div class="ppdb-label">NIK Ayah</div>
                <div class="ppdb-value"><?= $record['father_nik'] ?></div>
            </div>
            <div class="col-md-3">
                <div class="ppdb-label">Pekerjaan Ayah</div>
                <div class="ppdb-value"><?= $record['father_job'] ?></div>
            </div>

            <div class="col-md-6">
                <div class="ppdb-label">Nama Ibu</div>
                <div class="ppdb-value"><?= $record['mother_name'] ?></div>
            </div>
            <div class="col-md-3">
                <div class="ppdb-label">NIK Ibu</div>
                <div class="ppdb-value"><?= $record['mother_nik'] ?></div>
            </div>
            <div class="col-md-3">
                <div class="ppdb-label">Pekerjaan Ibu</div>
                <div class="ppdb-value"><?= $record['mother_job'] ?></div>
            </div>
        </div>
    </div>

    <!-- ================= SEKOLAH ================= -->
    <div class="ppdb-section">
        <div class="ppdb-title">
            <i class="fas fa-school me-2"></i> Sekolah Asal
        </div>

        <div class="row g-3">
            <div class="col-md-6">
                <div class="ppdb-label">Nama Sekolah</div>
                <div class="ppdb-value"><?= $record['school_origin'] ?></div>
            </div>
            <div class="col-md-3">
                <div class="ppdb-label">NPSN</div>
                <div class="ppdb-value"><?= $record['school_npsn'] ?></div>
            </div>
            <div class="col-md-3">
                <div class="ppdb-label">Tahun Lulus</div>
                <div class="ppdb-value"><?= $record['graduation_year'] ?></div>
            </div>
        </div>
    </div>

    <!-- ================= DOKUMEN ================= -->
    <div class="ppdb-section">
        <div class="ppdb-title">
            <i class="fas fa-file-alt me-2"></i> Dokumen Upload
        </div>

        <div class="row g-3">
            <?php
            $docs = [
                'Foto' => 'photo_file',
                'KK' => 'kk_file',
                'Akta' => 'akta_file',
                'KIP' => 'kip_file',
                'Ijazah' => 'ijazah_file',
                'SKL' => 'skl_file',
            ];
            ?>

            <?php foreach ($docs as $label => $field): ?>
            <div class="col-md-4">
                <div class="doc-box">
                    <div class="ppdb-label"><?= $label ?></div>
                    <?php if (!empty($record[$field])): ?>
                        <a href="<?= $base.$record[$field] ?>" target="_blank"
                           class="btn btn-sm btn-outline-primary mt-1">
                            <i class="fas fa-eye"></i> Lihat Dokumen
                        </a>
                    <?php else: ?>
                        <div class="text-muted small">Tidak ada</div>
                    <?php endif ?>
                </div>
            </div>
            <?php endforeach ?>

            <!-- RAPOR -->
            <div class="col-12">
                <div class="doc-box">
                    <div class="ppdb-label">Rapor</div>
                    <?php if ($rapors): ?>
                        <?php foreach ($rapors as $i => $r): ?>
                            <a href="<?= $base.$r ?>" target="_blank"
                               class="btn btn-sm btn-outline-success me-1 mt-1">
                                Rapor <?= $i+1 ?>
                            </a>
                        <?php endforeach ?>
                    <?php else: ?>
                        <div class="text-muted small">Tidak ada</div>
                    <?php endif ?>
                </div>
            </div>
        </div>
    </div>
            <div class="text-end mt-3">
                <a href="<?= site_url('ppdb/admin') ?>" class="btn btn-secondary">
                    Kembali
                </a>

</div>

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