<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <title>Cetak Rekap Penilaian</title>
    <style>
        /* 1. SETUP HALAMAN */
        @page { 
            /* UBAH DISINI: Margin bawah (bottom) diperbesar sedikit (15mm) 
               agar muat untuk Footer "Dicetak oleh..." */
            margin: 5mm 8mm 15mm 8mm; 
            size: auto; 
        }
        
        body { 
            font-family: 'Times New Roman', serif; 
            font-size: 9pt; 
            color: #000; 
            -webkit-print-color-adjust: exact; 
            margin: 0; padding: 0;
            width: 100%;
        }

        .page-container { 
            page-break-after: always; 
            position: relative;
            width: 100%;
        }
        .page-container:last-child { page-break-after: auto; }

        /* HEADER & SUB-HEADER (TETAP SAMA) */
        .header { 
            text-align: center; 
            margin-bottom: 10px; 
            text-transform: uppercase; 
            font-weight: bold; 
            line-height: 1.2; 
            font-size: 11pt; 
        }
        
        .sub-header { 
            display: flex; 
            justify-content: space-between; 
            margin-bottom: 5px; 
            font-weight: bold; 
            border-bottom: 2px solid #000; 
            padding-bottom: 5px;
            font-size: 9pt; 
            padding-left: 50px; 
            padding-right: 50px;
        }
        
        /* TABEL (TETAP SAMA) */
        table { 
            width: 99%; 
            margin: 0 auto; 
            border-collapse: collapse; 
            margin-bottom: 5px; 
            table-layout: fixed; 
        }
        
        th, td { 
            border: 1px solid #000; 
            padding: 2px 1px; 
            text-align: center; 
            vertical-align: middle; 
            font-size: 9pt; 
            overflow: hidden; 
            white-space: nowrap; 
            text-overflow: ellipsis; 
            height: 14px; 
        }
        
        th { background-color: #e0e0e0; font-weight: bold; height: 18px; }
        td.text-left { text-align: left; padding-left: 4px; }

        /* LEGEND & TTD (TETAP SAMA) */
        .footer-legend { 
            width: 99%; margin: 0 auto 10px auto; 
            font-size: 8pt; 
            border: 1px solid #000; 
            padding: 3px; 
            box-sizing: border-box; 
        }
        .legend-title { font-weight: bold; text-decoration: underline; margin-bottom: 0px; }
        .legend-item { display: block; margin-right: 10px; }

        .ttd-container {
            width: 99%; margin: 0 auto;
            display: flex;
            justify-content: flex-end; 
            page-break-inside: avoid; 
        }
        
        .ttd-box { 
            width: 220px; 
            text-align: left; 
            font-size: 9pt;
        }
        
        .ttd-date { margin-bottom: 2px; }
        .ttd-role { font-weight: bold; margin-bottom: 50px; } 
        .ttd-name { font-weight: bold; text-decoration: underline; }

        /* --- TAMBAHAN BARU: CSS FOOTER --- */
        .print-footer {
            position: fixed; /* Kunci agar muncul di tiap halaman */
            bottom: 0;
            left: 0;
            right: 0;
            width: 100%;
            text-align: right; /* Teks rata kanan */
            font-size: 8pt;
            font-style: italic;
            color: #444;
            padding-right: 8mm; /* Sesuaikan dengan margin kanan halaman */
            background-color: #fff; /* Latar putih agar tulisan jelas */
        }
    </style>
</head>
<body onload="window.print()">

<div class="print-footer">
    Dicetak dari Sistem Informasi Akademik | 
    Dicetak oleh: <?php echo e(Auth::user()->name ?? 'User'); ?> | 
    Tanggal: <?php echo e(\Carbon\Carbon::now()->isoFormat('D MMMM Y HH:mm')); ?>

</div>

<?php $__currentLoopData = $groupedData; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $groupKey => $penilaians): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
    <?php
        $firstItem = $penilaians->first();
        $className = $firstItem->kelas->nama_kelas;
        $allStudents = \App\Models\Student::where('class', $className)->orderBy('name', 'asc')->get();
    ?>

    <div class="page-container">
        
        <div class="header">
            REKAPITULASI NILAI SISWA<br>
            SMKN 10 MAKASSAR
        </div>

        
        <div class="sub-header">
            <div style="text-align: left;">
                Kelas : <?php echo e($className); ?><br>
                Mapel : <?php echo e($firstItem->subject->name); ?>

            </div>
            <div style="text-align: right;">
                Jenis : <?php echo e($firstItem->jenis_penilaian); ?><br>
                Tahun : <?php echo e(date('Y')); ?>

            </div>
        </div>

        
        <table>
            <colgroup>
                <col style="width: 5%">  
                <col style="width: 12%"> 
                <col style="width: 35%"> 
                
                <?php 
                    $sisaLebar = 48; 
                    $jumlahKolomNilai = $penilaians->count() + 1; 
                    $lebarPerKolom = $sisaLebar / $jumlahKolomNilai;
                ?>
                
                <?php $__currentLoopData = $penilaians; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $p): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <col style="width: <?php echo e($lebarPerKolom); ?>%">
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                <col style="width: <?php echo e($lebarPerKolom); ?>%"> 
            </colgroup>

            <thead>
                <tr>
                    <th>No</th>
                    <th>NIS</th>
                    <th>Nama Siswa</th>
                    <?php $__currentLoopData = $penilaians; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $p): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <th><?php echo e($index + 1); ?></th>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    <th>Rata-rata</th>
                </tr>
            </thead>
            <tbody>
                <?php if($allStudents->isEmpty()): ?>
                    <tr><td colspan="<?php echo e($penilaians->count() + 4); ?>">Data siswa tidak ditemukan.</td></tr>
                <?php else: ?>
                    <?php $__currentLoopData = $allStudents; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $i => $student): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <tr>
                            <td><?php echo e($i + 1); ?></td>
                            <td><?php echo e($student->nis ?? '-'); ?></td>
                            <td class="text-left"><?php echo e($student->name); ?></td>

                            <?php 
                                $totalScore = 0; 
                                $countScore = 0; // Untuk mencatat apakah siswa punya minimal 1 nilai
                            ?>

                            <?php $__currentLoopData = $penilaians; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $p): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <?php
                                    $detail = $p->details->where('siswa_id', $student->id)->first();
                                    // Jika null atau kosong, default ke '-'
                                    $nilai = ($detail && $detail->nilai !== null && $detail->nilai !== '') ? $detail->nilai : '-'; 

                                    if(is_numeric($nilai)) { 
                                        $totalScore += $nilai; 
                                        $countScore++; 
                                    } 
                                ?>
                                <td><?php echo e($nilai); ?></td>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                            
                            <td>
                                <?php if($countScore > 0 && $penilaians->count() > 0): ?> 
                                    
                                    <?php echo e(round($totalScore / $penilaians->count(), 0)); ?> 
                                <?php else: ?> 
                                    - 
                                <?php endif; ?>
                            </td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                <?php endif; ?>
            </tbody>
        </table>

        
        <div class="footer-legend">
            <div class="legend-title">Keterangan:</div>
            <?php $__currentLoopData = $penilaians; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $p): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <span class="legend-item">
                    <strong><?php echo e($index + 1); ?></strong>=<?php echo e($p->topik ?? 'Topik Kosong'); ?> 
                    <i>(<?php echo e(\Carbon\Carbon::parse($p->tanggal)->format('d/m/y')); ?>)</i>;
                </span>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </div>

        
        <div class="ttd-container">
            <div class="ttd-box">
                <div class="ttd-date">Makassar, <?php echo e(\Carbon\Carbon::now()->isoFormat('D MMMM Y')); ?></div>
                <div class="ttd-role">Guru Mata Pelajaran,</div>
                
                <div class="ttd-name"><?php echo e(Auth::user()->name); ?></div>
                <div class="ttd-nip">NIP. <?php echo e(Auth::user()->nip); ?></div>
            </div>
        </div>
    </div>
<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

</body>
</html><?php /**PATH /home/vol15_7/infinityfree.com/if0_40829333/sislajar-skansa.gt.tc/htdocs/resources/views/pages/pembelajaran/penilaian/print.blade.php ENDPATH**/ ?>