<?php $__env->startSection('content'); ?>

<style>
    /* --- HANYA CSS SPESIFIK HALAMAN INI (Prota) --- */
    /* Warna elemen standar (Modal, Tabel, Input) sudah diatur secara terpusat di app.blade.php */
    
    .accordion-prota .accordion-item {
        border: 1px solid var(--border-color);
        border-radius: 16px !important;
        margin-bottom: 20px;
        box-shadow: 0 4px 15px rgba(0,0,0,0.05);
        overflow: hidden;
        background-color: transparent;
    }
    .accordion-prota .accordion-button {
        font-size: 1.05rem;
        padding: 1.25rem 1.5rem;
    }
    .accordion-prota .accordion-body {
        padding: 0;
    }
    
    /* Helper Kustom Tambahan */
    .bg-inner-card {
        background-color: var(--hover-bg);
    }
    .btn-pill { 
        border-radius: 50rem !important; 
    }
</style>

<div class="container py-4">
    
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h2 class="fw-bold"><i class="bi bi-calendar-check me-2 text-primary"></i>Program Tahunan (Prota)</h2>
            <p class="text-muted mb-0">Kelola rencana penetapan alokasi waktu satu tahun ajaran.</p>
        </div>
        <div class="d-flex gap-2">
            <button type="button" class="btn btn-outline-secondary btn-pill px-4 shadow-sm" data-bs-toggle="modal" data-bs-target="#modalCetakProta">
                <i class="bi bi-printer me-1"></i> Cetak
            </button>
            <button type="button" class="btn btn-primary btn-pill px-4 fw-bold shadow-sm" data-bs-toggle="modal" data-bs-target="#modalTambah">
                <i class="bi bi-plus-circle me-1"></i> Tambah Prota
            </button>
        </div>
    </div>

    
    <?php if(session('success')): ?>
    <div class="alert alert-success alert-dismissible fade show shadow-sm border-0 border-start border-success border-4 bg-success bg-opacity-10 text-success rounded-4" role="alert">
        <i class="bi bi-check-circle-fill me-2"></i> <?php echo e(session('success')); ?>

        <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
    </div>
    <?php endif; ?>

    
    <?php
        $groupedProta = $programTahunans->groupBy(function($item) {
            return $item->subject->name ?? 'Tanpa Mata Pelajaran';
        })->map(function($group) {
            return $group->sortBy(function($item) {
                $gradeOrder = ['X' => 1, 'XI' => 2, 'XII' => 3];
                $grade = $gradeOrder[$item->grade_level] ?? 99;
                $sem = strtolower($item->semester) == 'ganjil' ? 1 : 2;
                return $grade . '-' . $sem;
            })->groupBy(function($item) {
                return $item->grade_level . '|' . $item->semester . '|' . $item->academic_year;
            }); 
        });
    ?>

    
    <div class="accordion accordion-prota" id="accordionProtaMapel">
        <?php $__empty_1 = true; $__currentLoopData = $groupedProta; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $subjectName => $kelasSemesterGroups): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
            <div class="accordion-item shadow-sm">
                <h2 class="accordion-header" id="heading-<?php echo e($loop->index); ?>">
                    <button class="accordion-button fw-bold collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapse-<?php echo e($loop->index); ?>" aria-expanded="false" aria-controls="collapse-<?php echo e($loop->index); ?>">
                        <div class="d-flex align-items-center w-100">
                            <div class="bg-primary bg-opacity-10 text-primary rounded-circle d-flex align-items-center justify-content-center me-3" style="width: 40px; height: 40px;">
                                <i class="bi bi-calendar-check-fill"></i>
                            </div>
                            <span class="fs-5"><?php echo e($subjectName); ?></span>
                            <?php $totalInMapel = $kelasSemesterGroups->flatten()->count(); ?>
                            <span class="badge bg-primary ms-auto me-3 rounded-pill px-3 py-2"><?php echo e($totalInMapel); ?> Data Prota</span>
                        </div>
                    </button>
                </h2>
                <div id="collapse-<?php echo e($loop->index); ?>" class="accordion-collapse collapse" aria-labelledby="heading-<?php echo e($loop->index); ?>">
                    <div class="accordion-body">
                        <div class="table-responsive">
                            
                            <table class="table table-hover align-middle mb-0">
                                <thead class="table-light">
                                    <tr>
                                        <th class="px-4 py-3" width="10%">Kelas</th>
                                        <th class="py-3 text-center" width="8%">Sem</th>
                                        <th class="py-3" width="30%">Kompetensi Inti / CP</th>
                                        <th class="py-3" width="30%">Materi Pokok</th>
                                        <th class="py-3 text-center" width="10%">Alokasi</th>
                                        <th class="py-3 text-center" width="12%">Aksi</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    
                                    <?php $__currentLoopData = $kelasSemesterGroups; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $groupKey => $items): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <?php
                                            $items = $items->values();
                                            $itemCount = $items->count();
                                            $totalJp = 0;
                                            
                                            $rowspansCp = [];
                                            $currentCp = null;
                                            $startIndex = 0;
                                            
                                            foreach ($items as $index => $item) {
                                                $totalJp += (int) filter_var($item->time_allocation, FILTER_SANITIZE_NUMBER_INT);
                                                
                                                if ($item->competency_standards === $currentCp) {
                                                    $rowspansCp[$startIndex]++;
                                                    $rowspansCp[$index] = 0;
                                                } else {
                                                    $currentCp = $item->competency_standards;
                                                    $startIndex = $index;
                                                    $rowspansCp[$startIndex] = 1;
                                                }
                                            }
                                        ?>

                                        <?php $__currentLoopData = $items; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <tr>
                                            <?php if($index === 0): ?>
                                                <td rowspan="<?php echo e($itemCount); ?>" class="px-4 align-middle border-end">
                                                    <span class="fw-bold d-block text-primary fs-5">Kelas <?php echo e($item->grade_level); ?></span>
                                                    <span class="badge bg-secondary bg-opacity-10 text-muted border rounded-pill mt-1"><?php echo e($item->academic_year); ?></span>
                                                </td>
                                                <td rowspan="<?php echo e($itemCount); ?>" class="text-center align-middle border-end">
                                                    <?php if(strtolower($item->semester) == 'ganjil'): ?>
                                                        <span class="badge bg-primary bg-opacity-10 text-primary border border-primary-subtle rounded-pill px-3 py-2">Ganjil</span>
                                                    <?php else: ?>
                                                        <span class="badge bg-success bg-opacity-10 text-success border border-success-subtle rounded-pill px-3 py-2">Genap</span>
                                                    <?php endif; ?>
                                                </td>
                                            <?php endif; ?>

                                            <?php if($rowspansCp[$index] > 0): ?>
                                                <td rowspan="<?php echo e($rowspansCp[$index]); ?>" class="align-middle border-end border-start bg-inner-card">
                                                    <div style="font-size: 0.9rem; white-space: pre-line; line-height: 1.6;">
                                                        <?php echo e($item->competency_standards); ?>

                                                    </div>
                                                </td>
                                            <?php endif; ?>

                                            <td class="align-middle">
                                                <div style="font-size: 0.9rem; white-space: pre-line; line-height: 1.6;">
                                                    <?php echo e($item->content_description); ?>

                                                </div>
                                            </td>

                                            <td class="text-center align-middle">
                                                <span class="badge bg-info bg-opacity-10 text-info border border-info-subtle rounded-pill px-3 py-2"><?php echo e($item->time_allocation); ?></span>
                                            </td>

                                            <td class="text-center align-middle">
                                                <div class="d-flex justify-content-center gap-2">
                                                    <button class="btn btn-sm btn-outline-warning rounded-circle" style="width:35px; height:35px;" title="Edit Data" data-bs-toggle="modal" data-bs-target="#modalEdit<?php echo e($item->id); ?>">
                                                        <i class="bi bi-pencil-square"></i>
                                                    </button>
                                                    <a href="<?php echo e(route('prota.printSingle', $item->id)); ?>" target="_blank" class="btn btn-sm btn-outline-success rounded-circle" style="width:35px; height:35px;" title="Cetak Prota ini">
                                                        <i class="bi bi-printer-fill"></i>
                                                    </a>
                                                    <form action="<?php echo e(route('prota.destroy', $item->id)); ?>" method="POST" onsubmit="return confirm('Yakin ingin menghapus data ini?')">
                                                        <?php echo csrf_field(); ?> <?php echo method_field('DELETE'); ?>
                                                        <button type="submit" class="btn btn-sm btn-outline-danger rounded-circle" style="width:35px; height:35px;" title="Hapus Data"><i class="bi bi-trash"></i></button>
                                                    </form>
                                                </div>
                                            </td>
                                        </tr>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        
                                        <tr class="table-secondary border-bottom">
                                            <td colspan="4" class="text-end fw-bold pe-4">
                                                Total Alokasi Waktu Kelas <?php echo e($items[0]->grade_level); ?> Semester <?php echo e(ucfirst($items[0]->semester)); ?>:
                                            </td>
                                            <td class="text-center fw-bold text-primary fs-5"><?php echo e($totalJp); ?> JP</td>
                                            <td></td> 
                                        </tr>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
            <div class="card modern-card border-0 py-5 text-center">
                <div class="card-body">
                    <div class="mb-3 text-muted opacity-50"><i class="bi bi-calendar-x" style="font-size: 4rem;"></i></div>
                    <h5 class="fw-bold">Belum ada data Program Tahunan.</h5>
                    <p class="text-muted">Klik tombol "Tambah Prota" untuk memulai perencanaan alokasi waktu Anda.</p>
                </div>
            </div>
        <?php endif; ?>
    </div>
</div>


<?php $__currentLoopData = $programTahunans; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
<div class="modal fade" id="modalEdit<?php echo e($item->id); ?>" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog modal-lg modal-dialog-centered">
        <div class="modal-content shadow-lg border-0 rounded-4">
            <div class="modal-header bg-warning border-0 rounded-top-4 py-3">
                <h5 class="modal-title fw-bold text-dark"><i class="bi bi-pencil-square me-2"></i> Edit Program Tahunan</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <form action="<?php echo e(route('prota.update', $item->id)); ?>" method="POST">
                <?php echo csrf_field(); ?> <?php echo method_field('PUT'); ?>
                <div class="modal-body p-4">
                    <div class="row">
                        <div class="col-md-6 mb-3">
                            <label class="form-label fw-bold small text-muted text-uppercase">Kelas</label>
                            <select name="grade_level" class="form-select rounded-pill py-2" required>
                                <option value="X" <?php echo e($item->grade_level == 'X' ? 'selected' : ''); ?>>Kelas X</option>
                                <option value="XI" <?php echo e($item->grade_level == 'XI' ? 'selected' : ''); ?>>Kelas XI</option>
                                <option value="XII" <?php echo e($item->grade_level == 'XII' ? 'selected' : ''); ?>>Kelas XII</option>
                            </select>
                        </div>
                        <div class="col-md-6 mb-3">
                            <label class="form-label fw-bold small text-muted text-uppercase">Semester</label>
                            <select name="semester" class="form-select rounded-pill py-2" required>
                                <option value="Ganjil" <?php echo e(strtolower($item->semester) == 'ganjil' ? 'selected' : ''); ?>>Ganjil</option>
                                <option value="Genap" <?php echo e(strtolower($item->semester) == 'genap' ? 'selected' : ''); ?>>Genap</option>
                            </select>
                        </div>
                    </div>
                    <div class="mb-3">
                        <label class="form-label fw-bold small text-muted text-uppercase">Kompetensi Inti / CP</label>
                        <textarea name="competency_standards" class="form-control rounded-4" rows="3" required><?php echo e($item->competency_standards); ?></textarea>
                    </div>
                    <div class="mb-3">
                        <label class="form-label fw-bold small text-muted text-uppercase">Materi Pokok</label>
                        <textarea name="content_description" class="form-control rounded-4" rows="3" required><?php echo e($item->content_description); ?></textarea>
                    </div>
                    <div class="mb-3">
                        <label class="form-label fw-bold small text-muted text-uppercase">Alokasi Waktu</label>
                        <input type="text" name="time_allocation" class="form-control rounded-pill py-2" value="<?php echo e($item->time_allocation); ?>" required>
                    </div>
                </div>
                <div class="modal-footer border-0 py-3 bg-inner-card rounded-bottom-4">
                    <button type="button" class="btn btn-outline-secondary btn-pill px-4" data-bs-dismiss="modal">Batal</button>
                    <button type="submit" class="btn btn-warning btn-pill px-5 fw-bold text-dark"><i class="bi bi-check-circle me-1"></i> Simpan Perubahan</button>
                </div>
            </form>
        </div>
    </div>
</div>
<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>


<div class="modal fade" id="modalTambah" tabindex="-1">
    <div class="modal-dialog modal-xl modal-dialog-centered"> 
        <div class="modal-content border-0 shadow-lg rounded-4">
            <div class="modal-header bg-primary border-0 text-white rounded-top-4 py-3">
                <h5 class="modal-title fw-bold"><i class="bi bi-plus-circle me-2"></i> Tambah Program Tahunan Baru</h5>
                <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
            </div>
            <form action="<?php echo e(route('prota.store')); ?>" method="POST">
                <?php echo csrf_field(); ?>
                <div class="modal-body p-4">
                    
                    
                    <div class="row">
                        <div class="col-md-6 mb-3">
                            <label class="form-label fw-bold small text-muted text-uppercase">Mata Pelajaran</label>
                            <select name="subject_id" id="input_subject" class="form-select rounded-pill py-2" required>
                                <option value="">Pilih Mapel...</option>
                                <?php $__currentLoopData = $subjects; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $subject): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($subject->id); ?>"><?php echo e($subject->name); ?> (<?php echo e($subject->code); ?>)</option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                        </div>
                        <div class="col-md-6 mb-3">
                            <label class="form-label fw-bold small text-muted text-uppercase">Tahun Ajaran</label>
                            <input type="text" name="academic_year" class="form-control rounded-pill py-2" placeholder="Cth: 2024/2025" required>
                        </div>
                    </div>

                    <div class="mb-3">
                        <label class="form-label fw-bold small text-muted text-uppercase">Kelas</label>
                        <select name="grade_level" id="input_grade" class="form-select rounded-pill py-2" required>
                            <option value="X">Kelas X</option>
                            <option value="XI">Kelas XI</option>
                            <option value="XII">Kelas XII</option>
                        </select>
                    </div>

                    <div class="mb-4">
                        <label class="form-label fw-bold small text-muted text-uppercase">Kompetensi Inti / Capaian Pembelajaran</label>
                        <textarea name="competency_standards" id="input_cp" class="form-control rounded-4" rows="3" placeholder="Masukkan detail kompetensi..." required></textarea>
                    </div>

                    
                    <div class="p-4 mb-4 rounded-4 border border-primary border-opacity-50" style="background: linear-gradient(145deg, rgba(59,130,246,0.1) 0%, rgba(59,130,246,0.02) 100%);">
                        <div class="mb-3">
                            <label class="form-label fw-bold text-primary fs-5 mb-2">
                                <i class="bi bi-robot me-2"></i> Generate Materi Pokok dengan AI
                            </label>
                            <input type="number" id="input_total_jp" class="form-control rounded-pill py-2" placeholder="Total JP 1 Tahun (Contoh: 72)">
                            <small class="text-primary opacity-75 d-block mt-2">AI akan otomatis membagi total JP ini ke dalam materi pokok Semester Ganjil dan Genap.</small>
                        </div>
                        <button type="button" id="btnGenerateAI" class="btn btn-primary btn-pill w-100 fw-bold shadow-sm py-2 mt-2">
                            <i class="bi bi-magic me-1"></i> Generate Materi Pokok
                        </button>
                    </div>

                    
                    <div id="materi_container">
                        <label class="form-label fw-bold small text-muted text-uppercase mb-3">Daftar Materi Pokok, Semester & Alokasi Waktu</label>
                        <div class="row mb-2 materi-row align-items-start">
                            <div class="col-md-7 mb-2">
                                <textarea name="content_description[]" class="form-control rounded-4" rows="2" placeholder="Masukkan materi pokok..." required></textarea>
                            </div>
                            <div class="col-md-2 mb-2">
                                <select name="semester[]" class="form-select rounded-pill" required>
                                    <option value="Ganjil">Ganjil</option>
                                    <option value="Genap">Genap</option>
                                </select>
                            </div>
                            <div class="col-md-2 mb-2">
                                <input type="number" name="time_allocation[]" class="form-control rounded-pill" placeholder="JP" required>
                            </div>
                            <div class="col-md-1 mb-2 text-center">
                                <button type="button" class="btn btn-outline-danger btn-remove-materi w-100 h-100 rounded-3" disabled>
                                    <i class="bi bi-trash"></i>
                                </button>
                            </div>
                        </div>
                    </div>
                    
                    <button type="button" id="btnAddMateri" class="btn btn-sm btn-outline-secondary btn-pill mt-3 px-4">
                        <i class="bi bi-plus-circle me-1"></i> Tambah Baris Manual
                    </button>
                    
                </div>
                <div class="modal-footer border-0 py-3 bg-inner-card rounded-bottom-4">
                    <button type="button" class="btn btn-outline-secondary btn-pill px-4" data-bs-dismiss="modal">Batal</button>
                    <button type="submit" class="btn btn-primary btn-pill px-5 fw-bold shadow-sm"><i class="bi bi-save me-1"></i> Simpan Data Prota</button>
                </div>
            </form>
        </div>
    </div>
</div>


<div class="modal fade" id="modalCetakProta" tabindex="-1">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content border-0 shadow-lg rounded-4">
            <div class="modal-header bg-secondary border-0 text-white rounded-top-4 py-3">
                <h5 class="modal-title fw-bold"><i class="bi bi-printer-fill me-2"></i> Filter Cetak Prota</h5>
                <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
            </div>
            <form action="<?php echo e(route('prota.print')); ?>" method="GET" target="_blank">
                <div class="modal-body p-4">
                    <div class="mb-3">
                        <label class="form-label fw-bold small text-muted text-uppercase">Pilih Mata Pelajaran</label>
                        <select name="subject_id" class="form-select rounded-pill py-2" required>
                            <option value="">-- Pilih Mapel --</option>
                            <?php $__currentLoopData = $subjects; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $subject): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($subject->id); ?>"><?php echo e($subject->name); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                        <div class="form-text text-muted mt-2">
                            Dokumen Prota akan dicetak berdasarkan mata pelajaran yang dipilih agar lebih rapi.
                        </div>
                    </div>
                </div>
                <div class="modal-footer border-0 py-3 bg-inner-card rounded-bottom-4">
                    <button type="button" class="btn btn-outline-secondary btn-pill px-4" data-bs-dismiss="modal">Batal</button>
                    <button type="submit" class="btn btn-primary btn-pill px-4 fw-bold shadow-sm">
                        <i class="bi bi-printer me-1"></i> Mulai Cetak
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>

<script>
    document.addEventListener('DOMContentLoaded', function () {
        const btnGenerateAI = document.getElementById('btnGenerateAI');
        const materiContainer = document.getElementById('materi_container');
        const btnAddMateri = document.getElementById('btnAddMateri');

        btnAddMateri.addEventListener('click', function() {
            addMateriRow('', '');
        });

        materiContainer.addEventListener('click', function(e) {
            const btn = e.target.closest('.btn-remove-materi');
            if(btn) {
                const rows = document.querySelectorAll('.materi-row');
                if(rows.length > 1) {
                    btn.closest('.materi-row').remove();
                }
            }
        });

        function addMateriRow(materiText = '', jpVal = '', semesterVal = 'Ganjil') {
            const isGanjil = (semesterVal.toLowerCase() === 'ganjil') ? 'selected' : '';
            const isGenap = (semesterVal.toLowerCase() === 'genap') ? 'selected' : '';

            const row = document.createElement('div');
            row.className = 'row mb-2 materi-row align-items-start';
            row.innerHTML = `
                <div class="col-md-7 mb-2">
                    <textarea name="content_description[]" class="form-control rounded-4" rows="2" required>${materiText}</textarea>
                </div>
                <div class="col-md-2 mb-2">
                    <select name="semester[]" class="form-select rounded-pill" required>
                        <option value="Ganjil" ${isGanjil}>Ganjil</option>
                        <option value="Genap" ${isGenap}>Genap</option>
                    </select>
                </div>
                <div class="col-md-2 mb-2">
                    <input type="number" name="time_allocation[]" class="form-control rounded-pill" value="${jpVal}" required>
                </div>
                <div class="col-md-1 mb-2 text-center">
                    <button type="button" class="btn btn-outline-danger btn-remove-materi w-100 h-100 rounded-3">
                        <i class="bi bi-trash"></i>
                    </button>
                </div>
            `;
            materiContainer.appendChild(row);
            document.querySelectorAll('.btn-remove-materi').forEach(btn => btn.disabled = false);
        }

        btnGenerateAI.addEventListener('click', async function() {
            const cp = document.getElementById('input_cp').value;
            const totalJp = document.getElementById('input_total_jp').value;
            const subjectSelect = document.getElementById('input_subject');
            const subject = subjectSelect.options[subjectSelect.selectedIndex].text;
            const gradeSelect = document.getElementById('input_grade');
            const grade = gradeSelect.options[gradeSelect.selectedIndex].text;

            if(!cp || !totalJp || subjectSelect.value === "") {
                alert('Mohon lengkapi pilihan Mata Pelajaran, Capaian Pembelajaran, dan Total JP terlebih dahulu!');
                return;
            }

            const originalText = btnGenerateAI.innerHTML;
            btnGenerateAI.innerHTML = '<span class="spinner-border spinner-border-sm"></span> Menyusun...';
            btnGenerateAI.disabled = true;

            try {
                const response = await fetch('<?php echo e(route("api.ai.generate-prota")); ?>', {
                    method: 'POST',
                    headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': '<?php echo e(csrf_token()); ?>' },
                    body: JSON.stringify({ cp, totalJp, subject, grade })
                });

                const data = await response.json();

                if(data.status === 'success') {
                    materiContainer.innerHTML = '<label class="form-label fw-bold small text-muted text-uppercase mb-3">Daftar Materi Pokok, Semester & Alokasi Waktu</label>';
                    data.results.forEach(item => {
                        addMateriRow(item.materi_pokok, item.alokasi_jp, item.semester);
                    });
                } else {
                    alert('Gagal Generate: ' + data.message);
                }
            } catch (error) {
                console.error('Error:', error);
                alert('Terjadi kesalahan koneksi ke server.');
            } finally {
                btnGenerateAI.innerHTML = originalText;
                btnGenerateAI.disabled = false;
            }
        });
    });
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home/vol15_7/infinityfree.com/if0_40829333/sislajar-skansa.gt.tc/htdocs/resources/views/pages/perangkat/prota/index.blade.php ENDPATH**/ ?>