<?php
// detail.php — Pengembangan Diri
require_once '../../config/config.php';
require_once '../../config/database.php';
require_once '../../core/helpers.php';
requireLogin();

$id   = (int)($_GET['id'] ?? 0);
$data = Database::fetchOne("SELECT * FROM pengembangan_diri WHERE id=?", [$id]);
if (!$data) { setFlash('error','Data tidak ditemukan.'); redirect(BASE_URL.'/modules/pengembangan_diri/index.php'); }

$pageTitle  = e($data['judul_kegiatan']);
$activePage = 'pengembangan';
require_once ROOT_PATH . '/views/layouts/header.php';
?>

<div class="page-header">
  <div class="page-header-title">
    <h1><i class="bi bi-award me-2 text-primary"></i>Detail Pengembangan Diri</h1>
    <nav><ol class="breadcrumb">
      <li class="breadcrumb-item"><a href="<?= BASE_URL ?>/modules/dashboard/index.php">Dashboard</a></li>
      <li class="breadcrumb-item"><a href="<?= BASE_URL ?>/modules/pengembangan_diri/index.php">Pengembangan Diri</a></li>
      <li class="breadcrumb-item active">Detail</li>
    </ol></nav>
  </div>
  <div class="d-flex gap-2">
    <?php if(isAdmin()): ?>
    <a href="form.php?id=<?= $id ?>" class="btn btn-sm btn-outline-warning"><i class="bi bi-pencil me-1"></i>Edit</a>
    <?php endif; ?>
    <?php if($data['sertifikat_file']): ?>
    <a href="<?= BASE_URL ?>/uploads/sertifikat/<?= e($data['sertifikat_file']) ?>" target="_blank" class="btn btn-sm btn-outline-success">
      <i class="bi bi-patch-check me-1"></i>Sertifikat
    </a>
    <?php endif; ?>
  </div>
</div>

<div class="row g-3">
  <div class="col-lg-8">
    <div class="card mb-3">
      <div class="card-header"><span class="card-header-title"><i class="bi bi-info-circle me-2"></i>Informasi Kegiatan</span></div>
      <div class="card-body">
        <div class="row g-3">
          <div class="col-sm-6"><div class="text-muted fs-tiny fw-700 text-uppercase mb-1">Jenis Kegiatan</div><div><span class="badge bg-primary-subtle text-primary"><?= e($data['jenis_kegiatan']) ?></span></div></div>
          <div class="col-sm-6"><div class="text-muted fs-tiny fw-700 text-uppercase mb-1">Jumlah JP</div><div class="fw-700 fs-5"><?= $data['jumlah_jp'] ?? '—' ?> JP</div></div>
          <div class="col-12"><div class="text-muted fs-tiny fw-700 text-uppercase mb-1">Judul Kegiatan</div><div class="fw-700"><?= e($data['judul_kegiatan']) ?></div></div>
          <div class="col-sm-6"><div class="text-muted fs-tiny fw-700 text-uppercase mb-1">Penyelenggara</div><div><?= e($data['penyelenggara']) ?></div></div>
          <div class="col-sm-6"><div class="text-muted fs-tiny fw-700 text-uppercase mb-1">Tempat</div><div><?= $data['tempat'] ? e($data['tempat']) : '—' ?></div></div>
          <div class="col-sm-6"><div class="text-muted fs-tiny fw-700 text-uppercase mb-1">Tanggal Pelaksanaan</div><div><?= formatTanggal($data['tanggal_mulai'],'d F Y') ?> s/d <?= formatTanggal($data['tanggal_selesai'],'d F Y') ?></div></div>
          <?php if($data['resume_materi']): ?>
          <div class="col-12">
            <div class="text-muted fs-tiny fw-700 text-uppercase mb-1">Resume Materi</div>
            <div class="p-3 bg-light rounded" style="font-size:.875rem;line-height:1.8"><?= nl2br(e($data['resume_materi'])) ?></div>
          </div>
          <?php endif; ?>
        </div>
      </div>
    </div>
  </div>
  <div class="col-lg-4">
    <div class="card">
      <div class="card-header"><span class="card-header-title"><i class="bi bi-patch-check me-2"></i>Sertifikat</span></div>
      <div class="card-body">
        <?php if($data['nomor_sertifikat']): ?>
        <div class="mb-2"><div class="text-muted fs-tiny fw-700 text-uppercase mb-1">Nomor Sertifikat</div><div><?= e($data['nomor_sertifikat']) ?></div></div>
        <?php endif; ?>
        <?php if($data['tanggal_sertifikat']): ?>
        <div class="mb-3"><div class="text-muted fs-tiny fw-700 text-uppercase mb-1">Tanggal Sertifikat</div><div><?= formatTanggal($data['tanggal_sertifikat'],'d F Y') ?></div></div>
        <?php endif; ?>
        <?php if($data['sertifikat_file']): ?>
        <a href="<?= BASE_URL ?>/uploads/sertifikat/<?= e($data['sertifikat_file']) ?>" target="_blank" class="btn btn-success w-100">
          <i class="bi bi-download me-1"></i>Download Sertifikat
        </a>
        <?php else: ?>
        <div class="text-center py-3 text-muted"><i class="bi bi-file-earmark-x fs-3 d-block mb-2"></i>Belum ada sertifikat</div>
        <?php endif; ?>
      </div>
    </div>
  </div>
</div>

<?php require_once ROOT_PATH . '/views/layouts/footer.php'; ?>
