

<?php $__env->startSection('title', 'Laporan Buku Rosak KKM'); ?>

<?php $__env->startSection('content_header'); ?>
    <h1><i class="fas fa-mosque mr-2"></i>Laporan Buku Rosak — Kelas Kafa Menengah</h1>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
    <div class="mb-3 no-print">
        <a href="<?php echo e(route('admin.dashboard')); ?>" class="btn btn-outline-secondary btn-sm">
            <i class="fas fa-arrow-left mr-1"></i> Kembali ke Dashboard
        </a>
        <button
            onclick="window.open('<?php echo e(route('admin.laporan.kkm-buku-rosak-cetak', ['tahun' => $tahun, 'daerah' => $daerah])); ?>', '_blank')"
            class="btn btn-primary btn-sm ml-2">
            <i class="fas fa-print mr-1"></i> Cetak Laporan
        </button>
    </div>

    <div class="d-flex justify-content-between align-items-center mb-3 flex-wrap">
        <h5 class="text-muted mb-2">
            <i class="fas fa-chart-bar mr-1"></i> Jumlah Buku Rosak KKM Mengikut Tingkatan
            <?php if($daerah): ?>
                — Daerah: <span class="badge badge-primary"><?php echo e($daerah); ?></span>
            <?php else: ?>
                — <span class="badge badge-secondary">Semua Daerah</span>
            <?php endif; ?>
            — Tahun: <span class="badge badge-info"><?php echo e($tahun); ?></span>
        </h5>
        <form method="GET" action="<?php echo e(route('admin.laporan.kkm-buku-rosak')); ?>" class="form-inline no-print">
            <label class="mr-2 text-muted"><i class="fas fa-map-marker-alt mr-1"></i>Daerah:</label>
            <select name="daerah" class="form-control form-control-sm mr-3" onchange="this.form.submit()">
                <option value="">Semua Daerah</option>
                <?php $__currentLoopData = $senarai_daerah; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $d): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <option value="<?php echo e($d); ?>" <?php echo e($d == $daerah ? 'selected' : ''); ?>><?php echo e($d); ?></option>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </select>
            <label class="mr-2 text-muted"><i class="fas fa-calendar-alt mr-1"></i>Tahun:</label>
            <select name="tahun" class="form-control form-control-sm" onchange="this.form.submit()">
                <?php $__currentLoopData = $senarai_tahun; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $t): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <option value="<?php echo e($t); ?>" <?php echo e($t == $tahun ? 'selected' : ''); ?>><?php echo e($t); ?></option>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </select>
        </form>
    </div>

    <div class="callout callout-info no-print">
        <h5><i class="fas fa-info-circle mr-1"></i> Formula</h5>
        <p class="mb-0"><strong>Buku Rosak</strong> = Stok Hingga Akhir − Elok Hingga Akhir</p>
    </div>

    <div class="row">
        <?php $__currentLoopData = $charts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $chart): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <div class="col-md-6 mb-4">
                <div class="card card-outline card-danger">
                    <div class="card-header">
                        <h3 class="card-title">
                            <strong><?php echo e($chart['darjah']); ?></strong>
                            <small class="text-muted ml-2">(Jumlah Rosak: <?php echo e(number_format($chart['total'])); ?>)</small>
                        </h3>
                    </div>
                    <div class="card-body">
                        <?php if(count($chart['labels']) > 0): ?>
                            <canvas id="barChart<?php echo e($loop->index); ?>" style="width:100%;height:260px"></canvas>
                        <?php else: ?>
                            <p class="text-muted py-4 text-center"><i class="fas fa-info-circle mr-1"></i>Tiada data buku
                                rosak.</p>
                        <?php endif; ?>
                    </div>
                    <?php if(count($chart['labels']) > 0): ?>
                        <div class="card-footer p-0">
                            <table class="table table-sm table-striped mb-0">
                                <thead class="thead-light">
                                    <tr>
                                        <th>Judul Buku</th>
                                        <th class="text-center">Stok</th>
                                        <th class="text-center">Elok</th>
                                        <th class="text-center">Rosak</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php $__currentLoopData = $chart['labels']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $idx => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <tr>
                                            <td class="small"><?php echo e($label); ?></td>
                                            <td class="text-center"><?php echo e(number_format($chart['stok'][$idx])); ?></td>
                                            <td class="text-center"><?php echo e(number_format($chart['elok'][$idx])); ?></td>
                                            <td
                                                class="text-center font-weight-bold <?php echo e($chart['values'][$idx] > 0 ? 'text-danger' : 'text-success'); ?>">
                                                <?php echo e(number_format($chart['values'][$idx])); ?>

                                            </td>
                                        </tr>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </tbody>
                            </table>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('js'); ?>
    <script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.7/dist/chart.umd.min.js"></script>
    <script>
        Chart.defaults.animation = false;
        Chart.defaults.responsive = true;

        (function() {
            if (window._adminKkmRosakRendered) return;
            window._adminKkmRosakRendered = true;

            <?php $__currentLoopData = $charts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $chart): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <?php if(count($chart['labels']) > 0): ?>
                    (function() {
                        var ctx = document.getElementById('barChart<?php echo e($loop->index); ?>').getContext('2d');
                        new Chart(ctx, {
                            type: 'bar',
                            data: {
                                labels: <?php echo json_encode($chart['labels']); ?>,
                                datasets: [{
                                    label: 'Rosak',
                                    data: <?php echo json_encode($chart['values']); ?>,
                                    backgroundColor: 'rgba(220,53,69,0.7)',
                                    borderColor: '#dc3545',
                                    borderWidth: 1
                                }]
                            },
                            options: {
                                responsive: true,
                                animation: false,
                                plugins: {
                                    legend: {
                                        position: 'top'
                                    }
                                },
                                scales: {
                                    x: {
                                        ticks: {
                                            font: {
                                                size: 10
                                            },
                                            maxRotation: 30
                                        }
                                    },
                                    y: {
                                        beginAtZero: true,
                                        ticks: {
                                            precision: 0
                                        }
                                    }
                                }
                            }
                        });
                    })();
                <?php endif; ?>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        })();
    </script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('adminlte::page', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\laragon\www\myspbt\resources\views/admin/laporan/kkm-buku-rosak.blade.php ENDPATH**/ ?>