<?php
require_once '../includes/header.php';
require_once '../includes/navbar.php';

// Ambil ID dari URL
$id = $_GET['id'] ?? 0;

// Ambil data pendidikan berdasarkan ID
$query = "SELECT ps.*, s.nisn, s.nis, s.nama_lengkap 
          FROM bind_pendidikan_siswa ps 
          JOIN bind_siswa s ON ps.id_siswa = s.id_siswa 
          WHERE ps.id_pendidikan = $id";
$result = mysqli_query($conn, $query);
$data = mysqli_fetch_assoc($result);

if (!$data) {
    echo "<script>
        Swal.fire({
            icon: 'error',
            title: 'Error',
            text: 'Data tidak ditemukan'
        }).then(() => {
            window.location.href = 'index.php';
        });
    </script>";
    exit;
}
?>

<div class="container mt-4">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h2><i class="fas fa-info-circle me-2"></i>Detail Data Pendidikan</h2>
        <a href="index.php" class="btn btn-secondary">
            <i class="fas fa-arrow-left me-1"></i> Kembali
        </a>
    </div>
    
    <div class="card border-0 shadow-lg">
        <div class="card-header bg-primary text-white py-3">
            <h5 class="card-title mb-0"><i class="fas fa-graduation-cap me-2"></i>Informasi Pendidikan Siswa</h5>
        </div>
        <div class="card-body p-4">
            <div class="row mb-4">
                <div class="col-md-6">
                    <h5 class="text-primary mb-3"><i class="fas fa-user-graduate me-2"></i>Data Siswa</h5>
                    <table class="table table-borderless">
                        <tr>
                            <th width="150">NISN</th>
                            <td><?= $data['nisn']; ?></td>
                        </tr>
                        <tr>
                            <th>NIS</th>
                            <td><?= $data['nis']; ?></td>
                        </tr>
                        <tr>
                            <th>Nama Lengkap</th>
                            <td><?= $data['nama_lengkap']; ?></td>
                        </tr>
                    </table>
                </div>
                <div class="col-md-6">
                    <h5 class="text-primary mb-3"><i class="fas fa-calendar-check me-2"></i>Penerimaan</h5>
                    <table class="table table-borderless">
                        <tr>
                            <th width="150">Diterima di Kelas</th>
                            <td><?= $data['diterima_di_kelas'] ? 'Kelas ' . $data['diterima_di_kelas'] : '-'; ?></td>
                        </tr>
                        <tr>
                            <th>Tanggal Diterima</th>
                            <td><?= $data['tanggal_diterima'] ? date('d/m/Y', strtotime($data['tanggal_diterima'])) : '-'; ?></td>
                        </tr>
                        <tr>
                            <th>Paket</th>
                            <td><?= $data['paket'] ?: '-'; ?></td>
                        </tr>
                    </table>
                </div>
            </div>
            
            <div class="row">
                <div class="col-md-6">
                    <h5 class="text-primary mb-3"><i class="fas fa-school me-2"></i>Sekolah Asal</h5>
                    <table class="table table-borderless">
                        <tr>
                            <th width="150">Asal Sekolah</th>
                            <td><?= $data['asal_sekolah'] ?: '-'; ?></td>
                        </tr>
                        <tr>
                            <th>Lama Belajar</th>
                            <td><?= $data['lama_belajar'] ?: '-'; ?></td>
                        </tr>
                        <tr>
                            <th>Pindahan Dari</th>
                            <td><?= $data['pindahan_dari'] ?: '-'; ?></td>
                        </tr>
                        <tr>
                            <th>Alasan Pindah</th>
                            <td><?= $data['alasan_pindah'] ?: '-'; ?></td>
                        </tr>
                    </table>
                </div>
                <div class="col-md-6">
                    <h5 class="text-primary mb-3"><i class="fas fa-file-certificate me-2"></i>Dokumen</h5>
                    <table class="table table-borderless">
                        <tr>
                            <th width="150">No. STTB</th>
                            <td><?= $data['no_sttb'] ?: '-'; ?></td>
                        </tr>
                        <tr>
                            <th>Tanggal STTB</th>
                            <td><?= $data['tgl_sttb'] ? date('d/m/Y', strtotime($data['tgl_sttb'])) : '-'; ?></td>
                        </tr>
                        <tr>
                            <th>No. SKHUN</th>
                            <td><?= $data['no_skhun'] ?: '-'; ?></td>
                        </tr>
                        <tr>
                            <th>Tanggal SKHUN</th>
                            <td><?= $data['tgl_skhun'] ? date('d/m/Y', strtotime($data['tgl_skhun'])) : '-'; ?></td>
                        </tr>
                    </table>
                </div>
            </div>
            
            <div class="d-flex justify-content-end mt-4">
                <a href="edit.php?id=<?= $data['id_pendidikan']; ?>" class="btn btn-warning me-2">
                    <i class="fas fa-edit me-1"></i> Edit
                </a>
                <a href="index.php" class="btn btn-secondary">
                    <i class="fas fa-list me-1"></i> Daftar Pendidikan
                </a>
            </div>
        </div>
    </div>
</div>

<?php
require_once '../includes/footer.php';
?>