<?php
require_once '../config/config.php';
require_once '../config/database.php';
require_once '../core/helpers.php';
requireLogin();

$pageTitle  = 'Cetak Laporan';
$activePage = 'laporan';

$sekolahList = Database::fetchAll("SELECT id, nama_sekolah FROM sekolah WHERE aktif=1 ORDER BY nama_sekolah");

require_once ROOT_PATH . '/views/layouts/header.php';
?>

<div class="page-header">
  <div class="page-header-title">
    <h1><i class="bi bi-printer me-2 text-primary"></i>Cetak Laporan</h1>
    <nav><ol class="breadcrumb"><li class="breadcrumb-item"><a href="<?= BASE_URL ?>/modules/dashboard/index.php">Dashboard</a></li><li class="breadcrumb-item active">Laporan</li></ol></nav>
  </div>
</div>

<div class="row g-3">
  <!-- Laporan Kegiatan -->
  <div class="col-md-6">
    <div class="card">
      <div class="card-header">
        <span class="card-header-title"><i class="bi bi-file-earmark-bar-graph me-2 text-danger"></i>Laporan Kegiatan Pendampingan</span>
      </div>
      <div class="card-body">
        <p class="text-muted mb-3" style="font-size:.85rem">Cetak rekapitulasi kegiatan pendampingan berdasarkan periode dan sekolah.</p>
        <form id="formLapKeg" target="_blank" action="<?= BASE_URL ?>/exports/laporan.php" method="GET">
          <input type="hidden" name="type" value="kegiatan">
          <div class="row g-2 mb-3">
            <?php if(!isSekolah()): ?>
            <div class="col-12">
              <label class="form-label">Sekolah</label>
              <select name="sekolah" class="form-select form-select-sm">
                <option value="">Semua Sekolah</option>
                <?php foreach($sekolahList as $s): ?>
                <option value="<?= $s['id'] ?>"><?= e($s['nama_sekolah']) ?></option>
                <?php endforeach; ?>
              </select>
            </div>
            <?php endif; ?>
            <div class="col-6">
              <label class="form-label">Bulan</label>
              <select name="bulan" class="form-select form-select-sm">
                <option value="">Semua Bulan</option>
                <?php $bn=['','Januari','Februari','Maret','April','Mei','Juni','Juli','Agustus','September','Oktober','November','Desember'];
                for($m=1;$m<=12;$m++): ?>
                <option value="<?= $m ?>"><?= $bn[$m] ?></option>
                <?php endfor; ?>
              </select>
            </div>
            <div class="col-6">
              <label class="form-label">Tahun</label>
              <select name="tahun" class="form-select form-select-sm">
                <?php for($y=date('Y');$y>=2020;$y--): ?>
                <option value="<?= $y ?>" <?= $y==date('Y')?'selected':'' ?>><?= $y ?></option>
                <?php endfor; ?>
              </select>
            </div>
            <div class="col-12">
              <label class="form-label">Status</label>
              <select name="status" class="form-select form-select-sm">
                <option value="">Semua Status</option>
                <option value="Draft">Draft</option>
                <option value="Terkirim">Terkirim</option>
                <option value="Disetujui">Disetujui</option>
              </select>
            </div>
          </div>
          <button type="submit" class="btn btn-danger w-100">
            <i class="bi bi-file-pdf me-2"></i>Buka Laporan
          </button>
        </form>
      </div>
    </div>
  </div>

  <!-- Laporan Pengembangan Diri -->
  <div class="col-md-6">
    <div class="card">
      <div class="card-header">
        <span class="card-header-title"><i class="bi bi-award me-2 text-warning"></i>Laporan Pengembangan Diri</span>
      </div>
      <div class="card-body">
        <p class="text-muted mb-3" style="font-size:.85rem">Cetak rekapitulasi kegiatan pengembangan diri dan sertifikat.</p>
        <form target="_blank" action="<?= BASE_URL ?>/exports/laporan_pengembangan.php" method="GET">
          <div class="row g-2 mb-3">
            <div class="col-6">
              <label class="form-label">Tahun</label>
              <select name="tahun" class="form-select form-select-sm">
                <?php for($y=date('Y');$y>=2020;$y--): ?>
                <option value="<?= $y ?>" <?= $y==date('Y')?'selected':'' ?>><?= $y ?></option>
                <?php endfor; ?>
              </select>
            </div>
            <div class="col-6">
              <label class="form-label">Jenis</label>
              <select name="jenis" class="form-select form-select-sm">
                <option value="">Semua Jenis</option>
                <?php foreach(['Diklat','Seminar','Workshop','Webinar','Bimtek','Lokakarya','Lainnya'] as $j): ?>
                <option value="<?= $j ?>"><?= $j ?></option>
                <?php endforeach; ?>
              </select>
            </div>
          </div>
          <button type="submit" class="btn btn-warning w-100">
            <i class="bi bi-file-pdf me-2"></i>Buka Laporan
          </button>
        </form>
      </div>
    </div>
  </div>

  <!-- Laporan Profil -->
  <div class="col-md-6">
    <div class="card">
      <div class="card-header">
        <span class="card-header-title"><i class="bi bi-person-badge me-2 text-info"></i>Laporan Profil Pendamping</span>
      </div>
      <div class="card-body">
        <p class="text-muted mb-3" style="font-size:.85rem">Cetak biodata lengkap pendamping sekolah beserta riwayat tugas.</p>
        <a href="<?= BASE_URL ?>/exports/laporan_profil.php" target="_blank" class="btn btn-info w-100">
          <i class="bi bi-file-pdf me-2"></i>Cetak Profil
        </a>
      </div>
    </div>
  </div>

  <!-- Laporan Sekolah -->
  <div class="col-md-6">
    <div class="card">
      <div class="card-header">
        <span class="card-header-title"><i class="bi bi-building me-2 text-success"></i>Laporan Data Sekolah</span>
      </div>
      <div class="card-body">
        <p class="text-muted mb-3" style="font-size:.85rem">Cetak daftar seluruh sekolah dampingan beserta informasi lengkapnya.</p>
        <a href="<?= BASE_URL ?>/exports/laporan_sekolah.php" target="_blank" class="btn btn-success w-100">
          <i class="bi bi-file-pdf me-2"></i>Cetak Data Sekolah
        </a>
      </div>
    </div>
  </div>
</div>

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