<?php 
include '../koneksi.php';
cek_akses(['Kepala', 'Super Admin']);

// Ambil parameter dari URL
$guru_id = isset($_GET['guru_id']) ? (int)$_GET['guru_id'] : 0;
$guru_nama = isset($_GET['guru_nama']) ? urldecode($_GET['guru_nama']) : '';

if($guru_id > 0 && empty($guru_nama)) {
    $query_guru = mysqli_query($conn, "SELECT full_name FROM users WHERE id = $guru_id AND role = 'Guru'");
    if($query_guru && mysqli_num_rows($query_guru) > 0) {
        $guru = mysqli_fetch_assoc($query_guru);
        $guru_nama = $guru['full_name'];
    }
}
?>

<!DOCTYPE html>
<html>
<head>
    <title>Formulir Telaah RPP/Modul Ajar</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/admin-lte@3.2/dist/css/adminlte.min.css">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="../assets/css/theme-istiqlal-green.css">
    <style>
        .form-container { max-width: 1200px; margin: 0 auto; }
        .section-card { margin-bottom: 20px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
        .section-header { background: #0b5e4e; color: white; padding: 10px 15px; font-weight: 600; }
        .section-body { background: white; padding: 15px; }
        .item-row { border-bottom: 1px solid #e2e8f0; padding: 12px 0; }
        .item-row:last-child { border-bottom: none; }
        .item-number { font-weight: 700; color: #0b5e4e; width: 35px; display: inline-block; }
        .item-text { display: inline-block; width: calc(100% - 350px); vertical-align: top; }
        .rating-group { display: inline-flex; gap: 15px; margin-left: 15px; align-items: center; }
        .rating-option { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; }
        .rating-option input { margin: 0; transform: scale(1.1); }
        .catatan-field { margin-top: 8px; margin-left: 35px; }
        .catatan-field input { width: 100%; padding: 6px 10px; border: 1px solid #cbd5e1; border-radius: 6px; font-size: 12px; }
        @media print { .no-print { display: none !important; } }
    </style>
</head>
<body class="hold-transition sidebar-mini layout-fixed">
<div class="wrapper">
    <?php include '../sidebar.php'; ?>
    
    <div class="content-wrapper">
        <div class="content-header">
            <div class="container-fluid">
                <div class="row mb-2">
                    <div class="col-sm-6">
                        <h1 class="m-0" style="font-size: 18px;"><i class="fas fa-book-open text-primary"></i> FORMULIR INSTRUMEN</h1>
                        <small>TELAAH RPP / MODUL AJAR (F-036-KM)</small>
                    </div>
                    <div class="col-sm-6">
                        <ol class="breadcrumb float-sm-right">
                            <li class="breadcrumb-item"><a href="../dashboard.php">Home</a></li>
                            <li class="breadcrumb-item"><a href="supervisi_menu.php">Supervisi</a></li>
                            <li class="breadcrumb-item active">Telaah RPP</li>
                        </ol>
                    </div>
                </div>
            </div>
        </div>

        <div class="content">
            <div class="container-fluid form-container">
                <form method="POST" action="cetak_dokumen.php" target="_blank" id="formRpp">
                    <input type="hidden" name="form_type" value="rpp">
                    
                    <!-- Data Guru -->
                    <div class="section-card">
                        <div class="section-header"><i class="fas fa-user"></i> Data Guru</div>
                        <div class="section-body">
                            <div class="row">
                                <div class="col-md-3 mb-2">
                                    <label class="small fw-bold">Nama Guru</label>
                                    <input type="text" name="nama_guru" class="form-control form-control-sm" value="<?= htmlspecialchars($guru_nama) ?>" required>
                                    <?php if($guru_nama): ?>
                                    <small class="text-success d-block">✓ Data otomatis dari jadwal supervisi</small>
                                    <?php endif; ?>
                                </div>
                                <div class="col-md-3 mb-2">
                                    <label class="small fw-bold">Bidang Studi</label>
                                    <input type="text" name="bidang_studi" class="form-control form-control-sm" required>
                                </div>
                                <div class="col-md-3 mb-2">
                                    <label class="small fw-bold">Kelas</label>
                                    <input type="text" name="kelas" class="form-control form-control-sm" required>
                                </div>
                                <div class="col-md-3 mb-2">
                                    <label class="small fw-bold">Tanggal/Waktu</label>
                                    <input type="text" name="tanggal_waktu" class="form-control form-control-sm" placeholder="25 Mei 2024 / 07:30" required>
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- A. Perumusan Indikator (1-6) -->
                    <div class="section-card">
                        <div class="section-header"><i class="fas fa-list"></i> A. Perumusan Indikator</div>
                        <div class="section-body">
                            <?php
                            $aspek_a = [
                                1 => 'Indikator sesuai dengan SKL-KI, dan KD',
                                2 => 'Meliputi dimensi sikap, keterampilan dan pengetahuan',
                                3 => 'Menggunakan kata kerja operasional yang mengandung satu perilaku',
                                4 => 'Mengandung satu perilaku yang dapat diobservasi',
                                5 => 'Mencakup level berpikir tinggi (analisis, evaluasi, atau mencipta)',
                                6 => 'Meliputi pengetahuan faktual, konseptual, prosedural, dan/atau metakognitif'
                            ];
                            foreach($aspek_a as $no => $text): ?>
                            <div class="item-row">
                                <div>
                                    <span class="item-number"><?= $no ?></span>
                                    <span class="item-text"><?= $text ?></span>
                                    <div class="rating-group">
                                        <label class="rating-option"><input type="radio" name="skor<?= $no ?>" value="1" class="skor-radio"> 1</label>
                                        <label class="rating-option"><input type="radio" name="skor<?= $no ?>" value="2" class="skor-radio"> 2</label>
                                        <label class="rating-option"><input type="radio" name="skor<?= $no ?>" value="3" class="skor-radio"> 3</label>
                                        <label class="rating-option"><input type="radio" name="skor<?= $no ?>" value="4" class="skor-radio"> 4</label>
                                    </div>
                                </div>
                                <div class="catatan-field">
                                    <input type="text" name="catatan<?= $no ?>" class="form-control form-control-sm" placeholder="Catatan...">
                                </div>
                            </div>
                            <?php endforeach; ?>
                        </div>
                    </div>

                    <!-- B. Perumusan Tujuan Pembelajaran (7-10) -->
                    <div class="section-card">
                        <div class="section-header"><i class="fas fa-bullseye"></i> B. Perumusan Tujuan Pembelajaran</div>
                        <div class="section-body">
                            <?php
                            $aspek_b = [
                                7 => 'Tujuan realistik, dapat dicapai melalui proses pembelajaran',
                                8 => 'Relevan dengan kompetensi dasar dan indikator',
                                9 => 'Mencakup pengembangan sikap, keterampilan dan pengetahuan',
                                10 => 'Mengandung unsur menciptakan karya'
                            ];
                            foreach($aspek_b as $no => $text): ?>
                            <div class="item-row">
                                <div>
                                    <span class="item-number"><?= $no ?></span>
                                    <span class="item-text"><?= $text ?></span>
                                    <div class="rating-group">
                                        <label class="rating-option"><input type="radio" name="skor<?= $no ?>" value="1" class="skor-radio"> 1</label>
                                        <label class="rating-option"><input type="radio" name="skor<?= $no ?>" value="2" class="skor-radio"> 2</label>
                                        <label class="rating-option"><input type="radio" name="skor<?= $no ?>" value="3" class="skor-radio"> 3</label>
                                        <label class="rating-option"><input type="radio" name="skor<?= $no ?>" value="4" class="skor-radio"> 4</label>
                                    </div>
                                </div>
                                <div class="catatan-field">
                                    <input type="text" name="catatan<?= $no ?>" class="form-control form-control-sm" placeholder="Catatan...">
                                </div>
                            </div>
                            <?php endforeach; ?>
                        </div>
                    </div>

                    <!-- C. Materi Pelajaran (11-17) -->
                    <div class="section-card">
                        <div class="section-header"><i class="fas fa-book"></i> C. Materi Pelajaran</div>
                        <div class="section-body">
                            <?php
                            $aspek_c = [
                                11 => 'Relevan dengan tujuan pembelajaran',
                                12 => 'Sesuai dengan potensi peserta didik',
                                13 => 'Kontekstual',
                                14 => 'Sesuai dengan perkembangan fisik, intelektual, emosional, sosial, dan spiritual siswa',
                                15 => 'Bermanfaat untuk peserta didik',
                                16 => 'Materi yang disajikan aktual',
                                17 => 'Relevan dengan kebutuhan siswa'
                            ];
                            foreach($aspek_c as $no => $text): ?>
                            <div class="item-row">
                                <div>
                                    <span class="item-number"><?= $no ?></span>
                                    <span class="item-text"><?= $text ?></span>
                                    <div class="rating-group">
                                        <label class="rating-option"><input type="radio" name="skor<?= $no ?>" value="1" class="skor-radio"> 1</label>
                                        <label class="rating-option"><input type="radio" name="skor<?= $no ?>" value="2" class="skor-radio"> 2</label>
                                        <label class="rating-option"><input type="radio" name="skor<?= $no ?>" value="3" class="skor-radio"> 3</label>
                                        <label class="rating-option"><input type="radio" name="skor<?= $no ?>" value="4" class="skor-radio"> 4</label>
                                    </div>
                                </div>
                                <div class="catatan-field">
                                    <input type="text" name="catatan<?= $no ?>" class="form-control form-control-sm" placeholder="Catatan...">
                                </div>
                            </div>
                            <?php endforeach; ?>
                        </div>
                    </div>

                    <!-- D. Media Belajar (18-21) -->
                    <div class="section-card">
                        <div class="section-header"><i class="fas fa-tv"></i> D. Media Belajar</div>
                        <div class="section-body">
                            <?php
                            $aspek_d = [
                                18 => 'Sesuai dengan tujuan pembelajaran',
                                19 => 'Memudahkan siswa menguasai materi pelajaran',
                                20 => 'Memfasilitasi siswa menerapkan pendekatan saintifik',
                                21 => 'Memberdayakan teknologi informasi dan komunikasi'
                            ];
                            foreach($aspek_d as $no => $text): ?>
                            <div class="item-row">
                                <div>
                                    <span class="item-number"><?= $no ?></span>
                                    <span class="item-text"><?= $text ?></span>
                                    <div class="rating-group">
                                        <label class="rating-option"><input type="radio" name="skor<?= $no ?>" value="1" class="skor-radio"> 1</label>
                                        <label class="rating-option"><input type="radio" name="skor<?= $no ?>" value="2" class="skor-radio"> 2</label>
                                        <label class="rating-option"><input type="radio" name="skor<?= $no ?>" value="3" class="skor-radio"> 3</label>
                                        <label class="rating-option"><input type="radio" name="skor<?= $no ?>" value="4" class="skor-radio"> 4</label>
                                    </div>
                                </div>
                                <div class="catatan-field">
                                    <input type="text" name="catatan<?= $no ?>" class="form-control form-control-sm" placeholder="Catatan...">
                                </div>
                            </div>
                            <?php endforeach; ?>
                        </div>
                    </div>

                    <!-- E. Metode Pembelajaran (22-25) -->
                    <div class="section-card">
                        <div class="section-header"><i class="fas fa-chalkboard"></i> E. Metode Pembelajaran</div>
                        <div class="section-body">
                            <?php
                            $aspek_e = [
                                22 => 'Sesuai dengan tujuan pembelajaran',
                                23 => 'Sesuai dengan pendekatan saintifik',
                                24 => 'Sesuai dengan model inkuiri, pembelajaran berbasis masalah, atau proyek',
                                25 => 'Mengembangkan kapasitas individu dan kerja sama peserta didik'
                            ];
                            foreach($aspek_e as $no => $text): ?>
                            <div class="item-row">
                                <div>
                                    <span class="item-number"><?= $no ?></span>
                                    <span class="item-text"><?= $text ?></span>
                                    <div class="rating-group">
                                        <label class="rating-option"><input type="radio" name="skor<?= $no ?>" value="1" class="skor-radio"> 1</label>
                                        <label class="rating-option"><input type="radio" name="skor<?= $no ?>" value="2" class="skor-radio"> 2</label>
                                        <label class="rating-option"><input type="radio" name="skor<?= $no ?>" value="3" class="skor-radio"> 3</label>
                                        <label class="rating-option"><input type="radio" name="skor<?= $no ?>" value="4" class="skor-radio"> 4</label>
                                    </div>
                                </div>
                                <div class="catatan-field">
                                    <input type="text" name="catatan<?= $no ?>" class="form-control form-control-sm" placeholder="Catatan...">
                                </div>
                            </div>
                            <?php endforeach; ?>
                        </div>
                    </div>

                    <!-- F. Rencana Kegiatan Pembelajaran (26-34) -->
                    <div class="section-card">
                        <div class="section-header"><i class="fas fa-calendar-alt"></i> F. Rencana Kegiatan Pembelajaran</div>
                        <div class="section-body">
                            <?php
                            $aspek_f = [
                                26 => 'Menampilkan kegiatan pendahuluan, inti, dan penutup',
                                27 => 'Menjelaskan tujuan pembelajaran',
                                28 => 'Merencanakan kegiatan siswa mengamati',
                                29 => 'Merencanakan kegiatan siswa menanya',
                                30 => 'Merancang kegiatan siswa mencoba',
                                31 => 'Merancang kegiatan siswa menalar atau mengasosiasi',
                                32 => 'Merancang kegiatan siswa membentuk jejaring atau mengomunikasikan produk penalarannya',
                                33 => 'Merancang kegiatan siswa berkarya atau mencipta',
                                34 => 'Mengandung rencana kegiatan tindak lanjut (penugasan, remedial, dan pengayaan)'
                            ];
                            foreach($aspek_f as $no => $text): ?>
                            <div class="item-row">
                                <div>
                                    <span class="item-number"><?= $no ?></span>
                                    <span class="item-text"><?= $text ?></span>
                                    <div class="rating-group">
                                        <label class="rating-option"><input type="radio" name="skor<?= $no ?>" value="1" class="skor-radio"> 1</label>
                                        <label class="rating-option"><input type="radio" name="skor<?= $no ?>" value="2" class="skor-radio"> 2</label>
                                        <label class="rating-option"><input type="radio" name="skor<?= $no ?>" value="3" class="skor-radio"> 3</label>
                                        <label class="rating-option"><input type="radio" name="skor<?= $no ?>" value="4" class="skor-radio"> 4</label>
                                    </div>
                                </div>
                                <div class="catatan-field">
                                    <input type="text" name="catatan<?= $no ?>" class="form-control form-control-sm" placeholder="Catatan...">
                                </div>
                            </div>
                            <?php endforeach; ?>
                        </div>
                    </div>

                    <!-- G. Penilaian (35-40) -->
                    <div class="section-card">
                        <div class="section-header"><i class="fas fa-clipboard-list"></i> G. Penilaian</div>
                        <div class="section-body">
                            <?php
                            $aspek_g = [
                                35 => 'Menilai ketercapaian indikator hasil belajar',
                                36 => 'Mengukur sikap, pengetahuan, dan keterampilan',
                                37 => 'Merancang penilaian otentik',
                                38 => 'Meliputi rancangan instrumen tes',
                                39 => 'Merancang penilaian tugas',
                                40 => 'Menetapkan pedoman penskoran'
                            ];
                            foreach($aspek_g as $no => $text): ?>
                            <div class="item-row">
                                <div>
                                    <span class="item-number"><?= $no ?></span>
                                    <span class="item-text"><?= $text ?></span>
                                    <div class="rating-group">
                                        <label class="rating-option"><input type="radio" name="skor<?= $no ?>" value="1" class="skor-radio"> 1</label>
                                        <label class="rating-option"><input type="radio" name="skor<?= $no ?>" value="2" class="skor-radio"> 2</label>
                                        <label class="rating-option"><input type="radio" name="skor<?= $no ?>" value="3" class="skor-radio"> 3</label>
                                        <label class="rating-option"><input type="radio" name="skor<?= $no ?>" value="4" class="skor-radio"> 4</label>
                                    </div>
                                </div>
                                <div class="catatan-field">
                                    <input type="text" name="catatan<?= $no ?>" class="form-control form-control-sm" placeholder="Catatan...">
                                </div>
                            </div>
                            <?php endforeach; ?>
                        </div>
                    </div>

                    <!-- Ringkasan Skor -->
                    <div class="section-card">
                        <div class="section-header"><i class="fas fa-calculator"></i> Ringkasan Penilaian</div>
                        <div class="section-body">
                            <div class="row">
                                <div class="col-md-3">
                                    <label class="small fw-bold">Jumlah Skor</label>
                                    <input type="text" name="total_skor" id="totalSkor" class="form-control form-control-sm" readonly style="background:#e9ecef">
                                </div>
                                <div class="col-md-3">
                                    <label class="small fw-bold">Nilai Maksimal</label>
                                    <input type="text" class="form-control form-control-sm" value="160" readonly style="background:#e9ecef">
                                </div>
                                <div class="col-md-3">
                                    <label class="small fw-bold">Nilai Akhir</label>
                                    <input type="text" name="nilai_akhir" id="nilaiAkhir" class="form-control form-control-sm" readonly style="background:#e9ecef">
                                </div>
                                <div class="col-md-3">
                                    <label class="small fw-bold">Kriteria</label>
                                    <input type="text" name="kriteria" id="kriteria" class="form-control form-control-sm" readonly style="background:#e9ecef">
                                </div>
                            </div>
                            <div class="mt-2">
                                <label class="small fw-bold">Keterangan</label>
                                <input type="text" name="keterangan" id="keterangan" class="form-control form-control-sm" readonly style="background:#e9ecef">
                            </div>
                        </div>
                    </div>

                    <!-- Kesimpulan & Rekomendasi -->
                    <div class="section-card">
                        <div class="section-header"><i class="fas fa-clipboard-list"></i> Kesimpulan & Rekomendasi</div>
                        <div class="section-body">
                            <div class="mb-2">
                                <label class="small fw-bold">Kesimpulan</label>
                                <textarea name="kesimpulan" class="form-control form-control-sm" rows="2"></textarea>
                            </div>
                            <div class="mb-2">
                                <label class="small fw-bold">Rekomendasi</label>
                                <textarea name="rekomendasi" class="form-control form-control-sm" rows="2"></textarea>
                            </div>
                        </div>
                    </div>

                    <!-- Tanda Tangan -->
                    <div class="section-card">
                        <div class="section-header"><i class="fas fa-signature"></i> Tanda Tangan</div>
                        <div class="section-body">
                            <div class="row">
                                <div class="col-md-4">
                                    <label class="small fw-bold">Jakarta, tanggal</label>
                                    <input type="text" name="tanggal_ttd" class="form-control form-control-sm" placeholder="25 Mei 2024" required>
                                </div>
                                <div class="col-md-4">
                                    <label class="small fw-bold">Penilai / Supervisor</label>
                                    <input type="text" name="supervisor" class="form-control form-control-sm" value="<?= $_SESSION['full_name'] ?>" readonly>
                                </div>
                                <div class="col-md-4">
                                    <label class="small fw-bold">NIK</label>
                                    <input type="text" name="nik" class="form-control form-control-sm" placeholder="Nomor Induk">
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="text-center mb-4 no-print">
                        <button type="submit" class="btn btn-primary btn-sm"><i class="fas fa-file-pdf"></i> Simpan & Cetak PDF</button>
                        <button type="button" class="btn btn-secondary btn-sm" onclick="window.print()"><i class="fas fa-print"></i> Print</button>
                        <a href="supervisi_menu.php?guru_id=<?= $guru_id ?>&guru_nama=<?= urlencode($guru_nama) ?>" class="btn btn-outline-secondary btn-sm">
                            <i class="fas fa-arrow-left"></i> Kembali
                        </a>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <footer class="main-footer no-print"><strong>&copy; <?= date('Y') ?> SIM ISTIQLAL</strong></footer>
</div>

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
$(document).ready(function() {
    $('.skor-radio').on('change', function() { hitungSkor(); });
    
    function hitungSkor() {
        var total = 0;
        for(var i=1; i<=40; i++) {
            var skor = $('input[name="skor'+i+'"]:checked').val();
            if(skor) total += parseInt(skor);
        }
        $('#totalSkor').val(total);
        var nilaiAkhir = (total / 160) * 100;
        $('#nilaiAkhir').val(nilaiAkhir.toFixed(2));
        var kriteria = '', keterangan = '';
        if(nilaiAkhir >= 86) { kriteria = 'Amat Baik'; keterangan = 'RPP/Modul Ajar sangat baik'; }
        else if(nilaiAkhir >= 70) { kriteria = 'Baik'; keterangan = 'RPP/Modul Ajar baik, beberapa aspek perlu ditingkatkan'; }
        else { kriteria = 'Kurang'; keterangan = 'RPP/Modul Ajar perlu perbaikan signifikan'; }
        $('#kriteria').val(kriteria);
        $('#keterangan').val(keterangan);
    }
});
</script>
</body>
</html>