<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Cetak Jadwal Mengajar</title>
    <style>
        /* Mengubah Orientasi Kertas Menjadi Landscape */
        @page { size: A4 landscape; margin: 1.5cm; }
        
        body { 
            font-family: 'Times New Roman', Times, serif; 
            font-size: 11pt; color: #000; margin: 0; padding: 0; 
            /* Memaksa browser mencetak warna latar belakang */
            -webkit-print-color-adjust: exact !important; 
            print-color-adjust: exact !important; 
        }
        .header { text-align: center; border-bottom: 3px double #000; padding-bottom: 10px; margin-bottom: 20px; }
        .header h2 { margin: 0 0 5px 0; font-size: 18pt; text-transform: uppercase; }
        .header h4 { margin: 0; font-size: 12pt; font-weight: normal; text-transform: uppercase; }
        
        .info-table { width: 100%; margin-bottom: 15px; font-size: 12pt; }
        .info-table td { padding: 3px 0; }
        
        /* Style Tabel Utama */
        .data-table { width: 100%; border-collapse: collapse; margin-bottom: 20px; font-size: 11pt; }
        .data-table th, .data-table td { border: 1px solid #000; padding: 6px 8px; text-align: left; }
        .data-table th { background-color: #e0e0e0; text-align: center; font-weight: bold; }
        .pekan-header { background-color: #f2f2f2; font-weight: bold; text-align: left !important; }
        
        /* Style Tabel Kalender */
        .calendar-container { 
            margin-top: 20px; 
            page-break-inside: avoid !important; 
            break-inside: avoid !important; 
            margin-bottom: 30px;
        }
        .calendar-title { text-align: center; font-weight: bold; font-size: 14pt; margin-bottom: 10px; background: #e0e0e0; padding: 5px; border: 1px solid #000; }
        .calendar-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
        .calendar-table tr { page-break-inside: avoid !important; break-inside: avoid !important; }
        .calendar-table th { border: 1px solid #000; background-color: #f2f2f2; padding: 6px; text-align: center; font-weight: bold; width: 14.28%; }
        .calendar-table td { border: 1px solid #000; vertical-align: top; height: 80px; padding: 4px; overflow: hidden; }
        .date-num { text-align: right; font-weight: bold; font-size: 10pt; margin-bottom: 5px; }
        .empty-cell { background-color: #fafafa; }
        
        /* Badge Event Kalender Dasar */
        .cal-event { 
            padding: 4px; 
            font-size: 8pt; 
            margin-bottom: 4px; 
            border: 1px solid #ddd; 
            border-left-width: 4px; 
            line-height: 1.2; 
            overflow: hidden;
            border-radius: 3px;
        }
        .cal-event strong { display: block; font-size: 8.5pt; margin-bottom: 2px; }
        
        .text-center { text-align: center !important; }
        .page-break { page-break-before: always; }
        
        .print-btn { position: fixed; bottom: 20px; right: 20px; padding: 12px 24px; font-size: 14pt; font-weight: bold; cursor: pointer; background: #0d6efd; color: white; border: none; border-radius: 8px; box-shadow: 0 4px 10px rgba(0,0,0,0.3); z-index: 1000; }
        
        @media print {
            .print-btn { display: none !important; }
        }
    </style>
</head>
<body>

    <?php
        $colors = [
            ['bg' => '#e8f0fe', 'border' => '#4e73df', 'text' => '#2e59d9'], // Blue
            ['bg' => '#e3fbf2', 'border' => '#1cc88a', 'text' => '#13855c'], // Green
            ['bg' => '#e8f8f9', 'border' => '#36b9cc', 'text' => '#258391'], // Cyan
            ['bg' => '#fef8e6', 'border' => '#f6c23e', 'text' => '#dda20a'], // Yellow
            ['bg' => '#fceceb', 'border' => '#e74a3b', 'text' => '#be2617'], // Red
            ['bg' => '#f2eef8', 'border' => '#6f42c1', 'text' => '#533190'], // Purple
            ['bg' => '#fff1e5', 'border' => '#fd7e14', 'text' => '#c25c03'], // Orange
        ];
    ?>

    <div class="header">
        <h2>Jadwal Mengajar Lengkap</h2>
        <h4>Tahun Ajaran <?php echo e(date('Y')); ?>/<?php echo e(date('Y', strtotime('+1 year'))); ?></h4>
    </div>

    <table class="info-table">
        <tr>
            <td width="120"><strong>Nama Guru</strong></td>
            <td width="15">:</td>
            <td><?php echo e($user->name); ?></td>
        </tr>
        <tr>
            <td><strong>Tanggal Cetak</strong></td>
            <td>:</td>
            <td><?php echo e(\Carbon\Carbon::now()->locale('id')->translatedFormat('l, d F Y')); ?></td>
        </tr>
    </table>

    <table class="data-table">
        <thead>
            <tr>
                <th width="5%">No</th>
                <th width="20%">Hari, Tanggal</th>
                <th width="15%">Kelas</th>
                <th width="45%">Mata Pelajaran</th>
                <th width="15%">Sistem</th>
            </tr>
        </thead>
        <tbody>
            <?php $__currentLoopData = $groupedByPekan; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $pekan => $jadwalPekan): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <tr>
                    <td colspan="5" class="pekan-header">Pekan Ke-<?php echo e($pekan); ?></td>
                </tr>
                <?php $__currentLoopData = $jadwalPekan; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <tr>
                        <td class="text-center"><?php echo e($index + 1); ?></td>
                        <td><?php echo e(\Carbon\Carbon::parse($item->tanggal)->locale('id')->translatedFormat('l, d M Y')); ?></td>
                        <td class="text-center"><?php echo e($item->class); ?></td>
                        <td><?php echo e($item->subject->name ?? '-'); ?></td>
                        <td class="text-center"><?php echo e(ucfirst($item->tipe_jadwal)); ?></td>
                    </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </tbody>
    </table>

    <div style="margin-top: 40px; text-align: right; page-break-after: always;">
        <p style="margin-right: 50px;">Mengetahui, .......................... <?php echo e(date('Y')); ?></p>
        <br><br><br>
        <p style="margin-right: 50px; font-weight: bold; text-decoration: underline;"><?php echo e($user->name); ?></p>
    </div>

    <div class="header">
        <h2>Kalender Jadwal Mengajar</h2>
    </div>

    <?php $__currentLoopData = $months; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $month): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
        <?php
            $startOfMonth = $month->copy()->startOfMonth();
            $daysInMonth = $month->daysInMonth;
            // dayOfWeek mengembalikan: 0 (Minggu), 1 (Senin), ... 6 (Sabtu)
            $firstDayOfWeek = $startOfMonth->dayOfWeek; 
        ?>
        
        <div class="calendar-container">
            <div class="calendar-title"><?php echo e(strtoupper($month->translatedFormat('F Y'))); ?></div>
            <table class="calendar-table">
                <thead>
                    <tr>
                        <th>MINGGU</th><th>SENIN</th><th>SELASA</th><th>RABU</th><th>KAMIS</th><th>JUMAT</th><th>SABTU</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        
                        <?php for($i = 0; $i < $firstDayOfWeek; $i++): ?>
                            <td class="empty-cell"></td>
                        <?php endfor; ?>
                        
                        
                        <?php for($day = 1; $day <= $daysInMonth; $day++): ?>
                            <?php
                                $currentDate = $month->copy()->day($day);
                                $dateString = $currentDate->format('Y-m-d');
                                $dailyEvents = $schedulesByDate->get($dateString, []);
                            ?>
                            
                            <td>
                                <div class="date-num"><?php echo e($day); ?></div>
                                <?php if(count($dailyEvents) > 0): ?>
                                    <?php $__currentLoopData = $dailyEvents; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $event): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <?php
                                            // Tentukan warna berdasarkan ID mapel
                                            $colorIdx = ($event->subject_id ?? 0) % count($colors);
                                            $theme = $colors[$colorIndex ?? $colorIdx];

                                            // Logika Pembuat Singkatan Kode Mapel
                                            $mapelName = $event->subject->name ?? '-';
                                            $kodeMapel = $event->subject->code ?? 'KD';
                                            
                                            // Jika kode tidak valid, buat singkatan otomatis dari nama mapel
                                            if (!$kodeMapel || $kodeMapel === 'KD' || strlen($kodeMapel) > 5) {
                                                $words = explode(' ', $mapelName);
                                                $kodeMapel = '';
                                                foreach($words as $w) {
                                                    if(isset($w[0])) $kodeMapel .= strtoupper($w[0]);
                                                }
                                                $kodeMapel = substr($kodeMapel, 0, 4);
                                            }
                                        ?>
                                        
                                        <div class="cal-event" style="background-color: <?php echo e($theme['bg']); ?>; border-left-color: <?php echo e($theme['border']); ?>;">
                                            <strong style="color: <?php echo e($theme['text']); ?>;">
                                                <?php echo e($kodeMapel); ?>

                                            </strong>
                                            <div style="color: #333; font-size: 7pt; margin-top: 1px;">Kls: <?php echo e($event->class); ?></div>
                                        </div>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                <?php endif; ?>
                            </td>
                            
                            
                            <?php if($currentDate->dayOfWeek == 6 && $day != $daysInMonth): ?>
                                </tr><tr>
                            <?php endif; ?>
                        <?php endfor; ?>
                        
                        

                        <?php $lastDayOfWeek = $month->copy()->endOfMonth()->dayOfWeek; ?>
                        <?php for($i = $lastDayOfWeek; $i < 6; $i++): ?>
                            <td class="empty-cell"></td>
                        <?php endfor; ?>
                    </tr>
                </tbody>
            </table>
        </div>
    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

    <button onclick="window.print()" class="print-btn">
        🖨️ Print Sekarang
    </button>

    <script>
        window.onload = function() {
            setTimeout(function() { window.print(); }, 1000);
        };
    </script>
</body>
</html><?php /**PATH /home/vol15_7/infinityfree.com/if0_40829333/sislajar-skansa.gt.tc/htdocs/resources/views/pages/pembelajaran/jadwal/print.blade.php ENDPATH**/ ?>