<?php include __DIR__ . '/../../views/layouts/header.php'; ?>
<div class="wrapper">
<?php include __DIR__ . '/../../views/layouts/sidebar.php'; ?>
<div class="main-content">
<?php include __DIR__ . '/../../views/layouts/topbar.php'; ?>

<div class="page-content">
  <div class="page-header d-flex justify-content-between align-items-start flex-wrap gap-2">
    <div>
      <h1><i class="bi bi-person-badge-fill me-2 text-primary"></i>Detail Guru</h1>
      <nav aria-label="breadcrumb">
        <ol class="breadcrumb">
          <li class="breadcrumb-item"><a href="<?= BASE_URL ?>/index.php?page=guru">Data Guru</a></li>
          <li class="breadcrumb-item active">Detail</li>
        </ol>
      </nav>
    </div>
    <div class="d-flex gap-2 no-print">
      <a href="<?= BASE_URL ?>/index.php?page=guru_edit&id=<?= $guru['id'] ?>" class="btn btn-warning btn-sm">
        <i class="bi bi-pencil me-1"></i> Edit
      </a>
      <a href="<?= BASE_URL ?>/index.php?page=guru" class="btn btn-outline-secondary btn-sm">
        <i class="bi bi-arrow-left me-1"></i> Kembali
      </a>
    </div>
  </div>

  <!-- Header -->
  <div class="detail-header mb-4">
    <div class="d-flex align-items-center gap-3 flex-wrap">
      <?php if (!empty($guru['foto'])): ?>
        <img src="<?= BASE_URL ?>/uploads/<?= e($guru['foto']) ?>"
             class="rounded-circle" style="width:80px;height:80px;object-fit:cover;border:3px solid rgba(255,255,255,.3);">
      <?php else: ?>
        <div style="width:80px;height:80px;border-radius:50%;background:rgba(255,255,255,.2);display:flex;align-items:center;justify-content:center;font-size:2rem;font-weight:700;color:#fff;">
          <?= strtoupper(substr($guru['nama'], 0, 1)) ?>
        </div>
      <?php endif; ?>
      <div>
        <h3 class="mb-1 text-white fw-700"><?= e($guru['nama']) ?></h3>
        <div class="d-flex gap-3 flex-wrap" style="opacity:.85;">
          <span><i class="bi bi-card-text me-1"></i>NIP: <?= e($guru['nip'] ?? '-') ?></span>
          <span><i class="bi bi-book me-1"></i><?= e($guru['mata_pelajaran'] ?? '-') ?></span>
          <span class="badge bg-<?= $guru['status'] === 'Aktif' ? 'success' : 'danger' ?>"><?= e($guru['status']) ?></span>
        </div>
      </div>
    </div>
  </div>

  <div class="row g-3">
    <div class="col-12 col-lg-8">
      <div class="card mb-3">
        <div class="card-header"><h6>Data Pribadi</h6></div>
        <div class="card-body">
          <div class="row g-3">
            <?php
            $fields = [
              'NIP'               => $guru['nip'] ?? '-',
              'Nama Lengkap'      => $guru['nama'],
              'Jenis Kelamin'     => $guru['jenis_kelamin'],
              'Tempat Lahir'      => $guru['tempat_lahir'] ?? '-',
              'Tanggal Lahir'     => formatTanggal($guru['tanggal_lahir'] ?? ''),
              'Agama'             => $guru['agama'] ?? '-',
              'Pendidikan'        => $guru['pendidikan'] ?? '-',
              'Jurusan'           => $guru['jurusan_pendidikan'] ?? '-',
              'Mata Pelajaran'    => !empty($guru['kode_mapel'])
                                     ? $guru['kode_mapel'] . (!empty($guru['nama_mapel']) && $guru['nama_mapel'] !== $guru['kode_mapel'] ? ' — ' . $guru['nama_mapel'] : '')
                                     : ($guru['mata_pelajaran'] ?? '-'),
              'Status Kepegawaian'=> $guru['status_kepegawaian'] ?? '-',
              'Tahun Masuk'       => $guru['tahun_masuk'] ?? '-',
              'No. HP'            => $guru['no_hp'] ?? '-',
              'Email'             => $guru['email'] ?? '-',
              'Alamat' => $guru['alamat'] ?? '-',
            ];
            foreach ($fields as $label => $value):
            ?>
            <div class="col-6 col-md-4">
              <div class="detail-label"><?= $label ?></div>
              <div class="detail-value"><?= e($value) ?></div>
            </div>
            <?php endforeach; ?>
          </div>
        </div>
      </div>
    </div>

    <div class="col-12 col-lg-4">
      <!-- Wali Kelas -->
      <div class="card">
        <div class="card-header"><h6><i class="bi bi-building me-2"></i>Wali Kelas</h6></div>
        <div class="card-body p-0">
          <?php if (empty($kelasWali)): ?>
            <div class="empty-state py-3"><p class="text-muted fs-sm">Bukan wali kelas</p></div>
          <?php else: ?>
            <?php foreach ($kelasWali as $k): ?>
            <div class="px-3 py-2 border-bottom">
              <div class="fw-600"><?= e($k['nama_kelas']) ?></div>
              <div class="text-muted fs-sm"><?= e($k['tahun_ajaran']) ?></div>
            </div>
            <?php endforeach; ?>
          <?php endif; ?>
        </div>
      </div>
    </div>
  </div>
</div>

<?php include __DIR__ . '/../../views/layouts/footer.php'; ?>
</div>
</div>
