

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

<?php $__env->startSection('content'); ?>
    <div class="card">
        <div class="card-header bg-success text-white">
            <h5 class="mb-0"><i class="bi bi-building me-1"></i> Sekolah</h5>
            <p class="mb-0 small text-white-50">Halaman manajemen data sekolah</p>
        </div>
        <div class="card-body">
                <div class="d-flex justify-content-between mb-3">
                    <div>
                        <p class="mb-0">Data Sekolah Sesuai Tahun Pelajaran</p>
                        <?php
                            $activePeriode = \App\Services\PeriodeService::getActive();
                        ?>
                        <?php if($activePeriode): ?>
                            <small class="text-muted">Tahun Pelajaran: <?php echo e($activePeriode->tahun_pelajaran); ?> &middot; Semester: <?php echo e($activePeriode->semester); ?></small>
                        <?php else: ?>
                            <small class="text-muted">Belum ada periode aktif</small>
                        <?php endif; ?>
                    </div>
                    <div>
                        <button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#tambahSekolahModal">Tambah Sekolah</button>
                    </div>
                </div>

                <?php if(session('success')): ?>
                    <div class="alert alert-success"><?php echo e(session('success')); ?></div>
                <?php endif; ?>

                <div class="table-responsive">
                    <table class="table table-bordered table-striped" style="table-layout: fixed;">
                        <thead>
                                <tr>
                                    <th style="width:80px;">NO</th>
                                    <th style="width:320px;">Nama Sekolah</th>
                                    <th style="width:120px;">NSS</th>
                                    <th style="width:120px;">NPSN</th>
                                    <th style="width:240px;">Kepala Sekolah</th>
                                    <th style="width:160px;">NIP</th>
                                    <th style="width:160px;">Kelurahan</th>
                                    <th style="width:160px;">Kecamatan</th>
                                    <th style="width:180px;">Kota/Kabupaten</th>
                                    <th style="width:120px;">Provinsi</th>
                                    <th style="width:420px;">Alamat</th>
                                    <th style="width:140px;">Telepon</th>
                                    <th style="width:220px;">Email</th>
                                    <th style="width:180px;">Tanggal Rapot 1</th>
                                    <th style="width:180px;">Tanggal Rapot 2</th>
                                    <th style="width:140px;">Aksi</th>
                                </tr>
                        </thead>
                        <tbody>
                            <?php $__empty_1 = true; $__currentLoopData = $sekolahs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $s): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                <tr>
                                    <td><?php echo e(($sekolahs->firstItem() ?? 0) + $loop->index); ?></td>
                                    <td><?php echo e($s->nama); ?></td>
                                    <td><?php echo e($s->nss); ?></td>
                                    <td><?php echo e($s->npsn); ?></td>
                                    <td><?php echo e($s->kepala_sekolah); ?></td>
                                    <td><?php echo e($s->nip); ?></td>
                                    <td><?php echo e($s->kelurahan); ?></td>
                                    <td><?php echo e($s->kecamatan); ?></td>
                                    <td><?php echo e($s->kota_kabupaten); ?></td>
                                    <td><?php echo e($s->provinsi); ?></td>
                                    <td><?php echo e(Str::limit($s->alamat, 60)); ?></td>
                                    <td><?php echo e($s->telepon); ?></td>
                                    <td><?php echo e($s->email); ?></td>
                                    <td><?php echo e($s->tanggal_rapot_1); ?></td>
                                    <td><?php echo e($s->tanggal_rapot_2); ?></td>
                                    <td>
                                        <button class="btn btn-sm btn-primary btn-edit" 
                                            data-id="<?php echo e($s->id); ?>"
                                            data-nama="<?php echo e($s->nama); ?>"
                                            data-npsn="<?php echo e($s->npsn); ?>"
                                            data-alamat="<?php echo e($s->alamat); ?>"
                                            data-telepon="<?php echo e($s->telepon); ?>"
                                            data-email="<?php echo e($s->email); ?>"
                                            data-tanggal_rapot_1="<?php echo e($s->tanggal_rapot_1); ?>"
                                            data-tanggal_rapot_2="<?php echo e($s->tanggal_rapot_2); ?>"
                                            data-bs-toggle="modal" data-bs-target="#editSekolahModal" title="Edit">
                                            <i class="bi bi-pencil" aria-hidden="true"></i>
                                        </button>

                                        <form action="<?php echo e(url('admin/data-umum/sekolah/' . $s->id)); ?>" method="POST" class="d-inline" onsubmit="return confirm('Yakin ingin menghapus sekolah ini?');">
                                            <?php echo csrf_field(); ?>
                                            <?php echo method_field('DELETE'); ?>
                                            <button class="btn btn-sm btn-danger" title="Hapus">
                                                <i class="bi bi-trash" aria-hidden="true"></i>
                                            </button>
                                        </form>
                                    </td>
                                </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                <tr>
                                    <td colspan="16" class="text-center">Belum ada data sekolah.</td>
                                </tr>
                            <?php endif; ?>
                        </tbody>
                    </table>
                </div>

                <?php echo $__env->make('admin.data-umum.sekolah.create', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                <?php echo $__env->make('admin.data-umum.sekolah.edit', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>

                <div class="d-flex justify-content-end mt-3">
                    <?php echo e($sekolahs instanceof \Illuminate\Pagination\LengthAwarePaginator ? $sekolahs->links() : ''); ?>

                </div>

                <script>
                    document.addEventListener('DOMContentLoaded', function () {
                        var editButtons = document.querySelectorAll('.btn-edit');
                        editButtons.forEach(function (btn) {
                            btn.addEventListener('click', function () {
                                var id = this.dataset.id;
                                document.getElementById('edit_nama').value = this.dataset.nama || '';
                                document.getElementById('edit_npsn').value = this.dataset.npsn || '';
                                document.getElementById('edit_alamat').value = this.dataset.alamat || '';
                                document.getElementById('edit_telepon').value = this.dataset.telepon || '';
                                        document.getElementById('edit_email').value = this.dataset.email || '';
                                        document.getElementById('edit_tanggal_rapot_1').value = this.dataset.tanggal_rapot_1 || '';
                                        document.getElementById('edit_tanggal_rapot_2').value = this.dataset.tanggal_rapot_2 || '';
                                var form = document.getElementById('editSekolahForm');
                                form.action = '/admin/data-umum/sekolah/' + id;
                            });
                        });
                    });
                </script>
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('admin.layout', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\App\laravel\laravel\resources\views/admin/data-umum/sekolah/index.blade.php ENDPATH**/ ?>