<?php
    $currentPath = current_url(true)->getPath();
    $currentPath = str_replace('/index.php', '', $currentPath);
    
    // Tentukan label tipe program
    $programLabel = 'Tahfidz KBM Pagi';
    if (isset($selectedProgram)) {
        $programLabel = match($selectedProgram['type']) {
            'pk' => 'Tahfidz PK',
            'boarding' => 'Tahfidz Boarding',
            default => 'Tahfidz KBM Pagi'
        };
    }

    $tabs = [
        ['title' => 'Dashboard', 'url' => '/guru/tahfidz', 'icon' => 'bi bi-house-door'],
        ['title' => 'Input Setoran', 'url' => '/guru/tahfidz/setoran', 'icon' => 'bi bi-pencil-square'],
        ['title' => 'Ceklis Hafalan', 'url' => '/guru/tahfidz/hafalan', 'icon' => 'bi bi-check2-square'],
        ['title' => 'Progress Juz', 'url' => '/guru/tahfidz/progress', 'icon' => 'bi bi-bar-chart-steps'],
        ['title' => 'Laporan', 'url' => '/guru/tahfidz/laporan', 'icon' => 'bi bi-clipboard-data'],
    ];
?>

<!-- Header Title Tipe Program (Bukan Nama Lengkap Program) -->
<div class="d-flex align-items-center justify-content-between mb-3 flex-wrap gap-2">
    <div>
        <h5 class="fw-bold mb-0">
            <i class="bi bi-book-half text-success me-2"></i><?= esc($programLabel) ?>
        </h5>
        <small class="text-muted">
            Tahun Pelajaran: <?= esc($activePeriod['year_name'] ?? '') ?> &bull; Semester <?= esc($activePeriod['semester'] ?? '') ?>
        </small>
    </div>
    <a href="/guru/tahfidz" class="btn btn-sm btn-outline-secondary">
        <i class="bi bi-arrow-left me-1"></i> Dashboard Utama
    </a>
</div>

<!-- Navigasi Fitur Horizontal -->
<div class="card border-0 shadow-sm mb-3">
    <div class="card-body p-2 d-flex align-items-center gap-2 flex-wrap">
        <?php foreach ($tabs as $t): ?>
            <?php 
                $isActive = ($currentPath === $t['url']);
            ?>
            <a href="<?= $t['url'] ?>?program_id=<?= $selectedProgram['id'] ?>" 
               class="btn btn-sm <?= $isActive ? 'btn-success fw-bold shadow-sm' : 'btn-light text-muted' ?> d-inline-flex align-items-center gap-2"
               style="border-radius: 6px; padding: 6px 14px; transition: all 0.2s;">
                <i class="<?= $t['icon'] ?>"></i>
                <span><?= $t['title'] ?></span>
            </a>
        <?php endforeach; ?>
    </div>
</div>
