

<?php $__env->startSection('title', 'Manajemen PSAJ - Admin Dinas'); ?>

<?php $__env->startSection('content'); ?>
<div class="container-fluid">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h1 class="h3 mb-2">Manajemen PSAJ</h1>
            <p class="text-muted mb-0">Penilaian Sumatif Akhir Jenjang - Semua Sekolah</p>
        </div>
    </div>

    <?php if(session('success')): ?>
        <div class="alert alert-success alert-dismissible fade show" role="alert">
            <?php echo e(session('success')); ?>

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

    <?php if(session('error')): ?>
        <div class="alert alert-danger alert-dismissible fade show" role="alert">
            <?php echo e(session('error')); ?>

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

    <!-- Filters -->
    <div class="card mb-3">
        <div class="card-body">
            <form method="GET" action="<?php echo e(route('admin-dinas.psaj.index')); ?>" class="row g-3">
                <div class="col-md-3">
                    <label class="form-label">Sekolah</label>
                    <select name="school_id" class="form-select">
                        <option value="">Semua Sekolah</option>
                        <?php $__currentLoopData = $schools; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $school): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($school->id); ?>" <?php echo e((request('school_id') == $school->id) ? 'selected' : ''); ?>>
                                <?php echo e($school->name); ?>

                            </option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>
                <div class="col-md-2">
                    <label class="form-label">Jenjang</label>
                    <select name="jenjang" class="form-select">
                        <option value="">Semua</option>
                        <?php $__currentLoopData = $jenjangOptions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($key); ?>" <?php echo e((request('jenjang') == $key) ? 'selected' : ''); ?>>
                                <?php echo e($key); ?>

                            </option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>
                <div class="col-md-2">
                    <label class="form-label">Status</label>
                    <select name="status" class="form-select">
                        <option value="">Semua</option>
                        <option value="draft" <?php echo e((request('status') == 'draft') ? 'selected' : ''); ?>>Draft</option>
                        <option value="final" <?php echo e((request('status') == 'final') ? 'selected' : ''); ?>>Final</option>
                    </select>
                </div>
                <div class="col-md-3">
                    <label class="form-label">Cari</label>
                    <input type="text" name="search" class="form-control" placeholder="Nama, NISN, NIK, No. Peserta" value="<?php echo e(request('search')); ?>">
                </div>
                <div class="col-md-2">
                    <label class="form-label">&nbsp;</label>
                    <div class="d-flex gap-2">
                        <button type="submit" class="btn btn-primary">
                            <i class="bi bi-search"></i> Filter
                        </button>
                        <a href="<?php echo e(route('admin-dinas.psaj.index')); ?>" class="btn btn-secondary">
                            <i class="bi bi-x"></i> Reset
                        </a>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <!-- Statistics -->
    <div class="row mb-4">
        <div class="col-md-3">
            <div class="card bg-primary text-white">
                <div class="card-body">
                    <div class="d-flex justify-content-between align-items-center">
                        <div>
                            <div class="text-white-50 small">Total Peserta</div>
                            <h4 class="mb-0"><?php echo e($participants->total()); ?></h4>
                        </div>
                        <i class="bi bi-people fs-1 opacity-50"></i>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-3">
            <div class="card bg-success text-white">
                <div class="card-body">
                    <div class="d-flex justify-content-between align-items-center">
                        <div>
                            <div class="text-white-50 small">Final (Terkunci)</div>
                            <h4 class="mb-0"><?php echo e($participants->where('is_locked', true)->count()); ?></h4>
                        </div>
                        <i class="bi bi-lock-fill fs-1 opacity-50"></i>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-3">
            <div class="card bg-warning text-dark">
                <div class="card-body">
                    <div class="d-flex justify-content-between align-items-center">
                        <div>
                            <div class="text-dark-50 small">Draft</div>
                            <h4 class="mb-0"><?php echo e($participants->where('is_locked', false)->count()); ?></h4>
                        </div>
                        <i class="bi bi-pencil fs-1 opacity-50"></i>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-3">
            <div class="card bg-info text-white">
                <div class="card-body">
                    <div class="d-flex justify-content-between align-items-center">
                        <div>
                            <div class="text-white-50 small">Dengan Foto</div>
                            <h4 class="mb-0"><?php echo e($participants->whereNotNull('photo')->count()); ?></h4>
                        </div>
                        <i class="bi bi-card-image fs-1 opacity-50"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Bulk Actions -->
    <div class="card mb-3">
        <div class="card-body">
            <button type="button" class="btn btn-danger" onclick="showBulkUnlockModal()" title="Buka kunci data peserta terpilih">
                <i class="bi bi-unlock me-2"></i>Buka Kunci (Bulk)
            </button>
            <small class="text-muted ms-2">Pilih peserta dengan checkbox untuk membuka kunci secara massal</small>
        </div>
    </div>

    <!-- Table -->
    <div class="card">
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th width="3%">
                                <input type="checkbox" id="selectAll" class="form-check-input" onchange="toggleSelectAll(this)">
                            </th>
                            <th width="5%">No</th>
                            <th width="15%">No. Peserta</th>
                            <th>Nama</th>
                            <th>Sekolah</th>
                            <th width="8%">Jenjang</th>
                            <th width="8%">Ketunaan</th>
                            <th width="8%">Status</th>
                            <th width="12%" class="text-center">Aksi</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $__empty_1 = true; $__currentLoopData = $participants; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $participant): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                            <tr class="<?php echo e($participant->is_locked ? 'table-secondary' : ''); ?>">
                                <td>
                                    <?php if($participant->is_locked): ?>
                                        <input type="checkbox" name="participant_ids[]" value="<?php echo e($participant->id); ?>" class="form-check-input participant-checkbox">
                                    <?php endif; ?>
                                </td>
                                <td><?php echo e(($participants->currentPage() - 1) * $participants->perPage() + $index + 1); ?></td>
                                <td>
                                    <small class="text-muted fw-bold"><?php echo e($participant->no_peserta); ?></small>
                                </td>
                                <td>
                                    <strong><?php echo e($participant->nama); ?></strong><br>
                                    <small class="text-muted">NISN: <?php echo e($participant->nisn); ?></small>
                                </td>
                                <td>
                                    <small><?php echo e($participant->school->name); ?></small>
                                </td>
                                <td>
                                    <span class="badge bg-primary"><?php echo e($participant->jenjang); ?></span>
                                </td>
                                <td>
                                    <span class="badge bg-info"><?php echo e($participant->disabilityType->code); ?></span>
                                </td>
                                <td>
                                    <?php if($participant->is_locked): ?>
                                        <span class="badge bg-success" title="Final pada <?php echo e($participant->submitted_at?->format('d/m/Y H:i')); ?>">
                                            <i class="bi bi-lock-fill me-1"></i>Final
                                        </span>
                                    <?php else: ?>
                                        <span class="badge bg-warning">
                                            <i class="bi bi-pencil me-1"></i>Draft
                                        </span>
                                    <?php endif; ?>
                                </td>
                                <td>
                                    <div class="btn-group btn-group-sm" role="group">
                                        <a href="<?php echo e(route('admin-dinas.psaj.show', $participant->id)); ?>" 
                                           class="btn btn-info" 
                                           title="Lihat Detail">
                                            <i class="bi bi-eye"></i>
                                        </a>
                                        <?php if($participant->is_locked): ?>
                                            <button type="button" 
                                                    class="btn btn-danger" 
                                                    title="Buka Kunci"
                                                    onclick="confirmUnlock(<?php echo e($participant->id); ?>)">
                                                <i class="bi bi-unlock"></i>
                                            </button>
                                        <?php endif; ?>
                                    </div>
                                </td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                            <tr>
                                <td colspan="9" class="text-center py-5 text-muted">
                                    <i class="bi bi-inbox fs-1 d-block mb-2"></i>
                                    Tidak ada data peserta PSAJ
                                </td>
                            </tr>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>
            
            <!-- Pagination -->
            <div class="mt-3">
                <?php echo e($participants->links()); ?>

            </div>
        </div>
    </div>
</div>

<!-- Unlock Confirmation Modal -->
<div class="modal fade" id="unlockModal" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header bg-danger text-white">
                <h5 class="modal-title">
                    <i class="bi bi-unlock me-2"></i>Konfirmasi Buka Kunci
                </h5>
                <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
            </div>
            <form id="unlockForm" method="POST">
                <?php echo csrf_field(); ?>
                <div class="modal-body">
                    <div class="alert alert-warning">
                        <i class="bi bi-exclamation-triangle me-2"></i>
                        <strong>Perhatian:</strong> Setelah kunci dibuka, sekolah dapat mengedit kembali data peserta ini.
                    </div>
                    <p>Apakah Anda yakin ingin membuka kunci data peserta ini?</p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Batal</button>
                    <button type="submit" class="btn btn-danger">
                        <i class="bi bi-unlock me-2"></i>Ya, Buka Kunci
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>

<!-- Bulk Unlock Modal -->
<div class="modal fade" id="bulkUnlockModal" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header bg-danger text-white">
                <h5 class="modal-title">
                    <i class="bi bi-unlock me-2"></i>Konfirmasi Buka Kunci Massal
                </h5>
                <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
            </div>
            <form id="bulkUnlockForm" method="POST" action="<?php echo e(route('admin-dinas.psaj.bulk-unlock')); ?>">
                <?php echo csrf_field(); ?>
                <div class="modal-body">
                    <div class="alert alert-warning">
                        <i class="bi bi-exclamation-triangle me-2"></i>
                        <strong>Perhatian:</strong> Setelah kunci dibuka, sekolah dapat mengedit kembali data peserta.
                    </div>
                    <p>Anda akan membuka kunci <strong id="selectedCount">0</strong> peserta.</p>
                    <p class="mb-0">Apakah Anda yakin?</p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Batal</button>
                    <button type="submit" class="btn btn-danger">
                        <i class="bi bi-unlock me-2"></i>Ya, Buka Kunci
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>

<?php $__env->startPush('scripts'); ?>
<script>
    function confirmUnlock(id) {
        const modal = new bootstrap.Modal(document.getElementById('unlockModal'));
        const form = document.getElementById('unlockForm');
        form.action = '<?php echo e(route("admin-dinas.psaj.unlock", ":id")); ?>'.replace(':id', id);
        modal.show();
    }
    
    function toggleSelectAll(checkbox) {
        const checkboxes = document.querySelectorAll('.participant-checkbox');
        checkboxes.forEach(cb => cb.checked = checkbox.checked);
    }
    
    function showBulkUnlockModal() {
        const checkboxes = document.querySelectorAll('.participant-checkbox:checked');
        
        if (checkboxes.length === 0) {
            alert('Silakan pilih minimal 1 peserta yang terkunci untuk dibuka kuncinya');
            return;
        }
        
        // Update count
        document.getElementById('selectedCount').textContent = checkboxes.length;
        
        // Clear existing hidden inputs
        const form = document.getElementById('bulkUnlockForm');
        const existingInputs = form.querySelectorAll('input[name="participant_ids[]"]');
        existingInputs.forEach(input => input.remove());
        
        // Add selected participant IDs to form
        checkboxes.forEach(checkbox => {
            const input = document.createElement('input');
            input.type = 'hidden';
            input.name = 'participant_ids[]';
            input.value = checkbox.value;
            form.appendChild(input);
        });
        
        // Show modal
        const modal = new bootstrap.Modal(document.getElementById('bulkUnlockModal'));
        modal.show();
    }
</script>
<?php $__env->stopPush(); ?>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\xampp\htdocs\appsuper\resources\views/admin-dinas/psaj/index.blade.php ENDPATH**/ ?>