<?php $__env->startSection('title', 'Jurnal Siswa'); ?>
<?php $__env->startSection('page-title', 'Jurnal Kegiatan Siswa'); ?>

<?php $__env->startSection('content'); ?>
<div class="card">
    <div class="card-header bg-white">
        <div class="row align-items-center mb-3">
            <div class="col-md-6">
                <h5 class="mb-0"><i class="fas fa-book me-2"></i>Jurnal Kegiatan Siswa</h5>
                <small class="text-muted">Lihat dan pantau jurnal kegiatan harian siswa magang</small>
            </div>
        </div>

        <!-- Form Filter -->
        <form method="GET" action="<?php echo e(route('pembimbing-sekolah.jurnal')); ?>">
            <div class="row g-3 align-items-end">
                <div class="col-lg-2 col-md-3">
                    <label class="form-label">Status</label>
                    <select class="form-select" name="status" id="status">
                        <option value="">Semua Status</option>
                        <option value="pending" <?php echo e(request('status') == 'pending' ? 'selected' : ''); ?>>Pending</option>
                        <option value="diterima" <?php echo e(request('status') == 'diterima' ? 'selected' : ''); ?>>Diterima</option>
                        <option value="ditolak" <?php echo e(request('status') == 'ditolak' ? 'selected' : ''); ?>>Ditolak</option>
                    </select>
                </div>

                <div class="col-lg-2 col-md-3">
                    <label class="form-label">Nama Siswa</label>
                    <input type="text" name="nama_siswa" class="form-control" 
                           placeholder="Cari nama siswa..." 
                           value="<?php echo e(request('nama_siswa')); ?>">
                </div>

                <div class="col-lg-2 col-md-3">
                    <label class="form-label">Tanggal Mulai</label>
                    <input type="date" name="tanggal_dari" class="form-control" value="<?php echo e(request('tanggal_dari')); ?>">
                </div>

                <div class="col-lg-2 col-md-3">
                    <label class="form-label">Tanggal Akhir</label>
                    <input type="date" name="tanggal_sampai" class="form-control" value="<?php echo e(request('tanggal_sampai')); ?>">
                </div>

                <div class="col-lg-4 col-md-12">
                    <div class="btn-group w-100" role="group">
                        <button type="submit" class="btn btn-primary">
                            <i class="fas fa-search me-1"></i> Cari
                        </button>
                        <?php if(request()->hasAny(['status', 'nama_siswa', 'tanggal_dari', 'tanggal_sampai'])): ?>
                            <a href="<?php echo e(route('pembimbing-sekolah.jurnal')); ?>" class="btn btn-outline-secondary">
                                <i class="fas fa-times me-1"></i> Reset
                            </a>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </form>
    </div>
    
    <div class="card-body">
        
        <div class="table-responsive d-none d-md-block">
            <table class="table table-striped table-hover">
                <thead class="table-dark">
                    <tr>
                        <th width="5%" class="text-center">No</th>
                        <th width="20%" class="text-center">Tanggal</th>
                        <th width="20%" class="text-center">Nama Siswa</th>
                        <th class="text-center">Status</th>
                        <th width="30%" class="text-center">Perencanaan</th>
                        <th class="text-center">Aksi</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__empty_1 = true; $__currentLoopData = $jurnal; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $j): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <tr>
                        <td><?php echo e($jurnal->firstItem() + $index); ?></td>
                        <td class="text-center">
                            <?php
                            $tanggal = \Carbon\Carbon::parse($j->tanggal);
                            $hariIndonesia = ['Minggu', 'Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat', 'Sabtu'];
                            $bulanIndonesia = ['', 'Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni', 'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember'];
                            ?>
                            <span class="fw-bold"><?php echo e($tanggal->day); ?> <?php echo e($bulanIndonesia[$tanggal->month]); ?> <?php echo e($tanggal->year); ?></span><br>
                            <small class="text-muted"><?php echo e($hariIndonesia[$tanggal->dayOfWeek]); ?></small>
                        </td>
                        <td class="text-center">
                            
                            <div class="text-start text-center">
                                <span class="fw-bold"><?php echo e($j->user->siswa->nama ?? $j->user->name); ?></span><br>
                                <small class="text-muted"><?php echo e($j->user->email); ?></small>
                            </div>
                        </td>
                        <td class="text-center">
                            <?php if($j->status_verifikasi == 'pending'): ?>
                                <span class="badge bg-warning text-dark">
                                    <i class="fas fa-clock"></i> Pending
                                </span>
                            <?php elseif($j->status_verifikasi == 'diterima'): ?>
                                <span class="badge bg-success">
                                    <i class="fas fa-check"></i> Diterima
                                </span>
                            <?php else: ?>
                                <span class="badge bg-danger">
                                    <i class="fas fa-times"></i> Ditolak
                                </span>
                            <?php endif; ?>
                        </td>
                        <td class="text-center">
                            <span class="d-inline-block text-truncate" style="max-width: 200px;" title="<?php echo e($j->perencanaan_kegiatan); ?>">
                                <?php echo e(\Str::limit($j->perencanaan_kegiatan, 80)); ?>

                            </span>
                        </td>
                        <td class="text-center">
                            <div class="btn-group text-center" role="group">
                                <a href="<?php echo e(route('pembimbing-sekolah.jurnal.show', $j->id)); ?>" class="btn btn-sm btn-info" title="Detail">
                                    <i class="fas fa-eye"></i>
                                </a>
                            </div>
                        </td>
                    </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <tr>
                        <td colspan="6" class="text-center text-muted py-4">
                            <?php if(request()->hasAny(['status', 'nama_siswa', 'tanggal_dari', 'tanggal_sampai'])): ?>
                                <i class="fas fa-search fa-3x mb-3"></i>
                                <p>Tidak ditemukan jurnal dengan kriteria yang dipilih</p>
                                <a href="<?php echo e(route('pembimbing-sekolah.jurnal')); ?>" class="btn btn-primary">Reset Filter</a>
                            <?php else: ?>
                                <i class="fas fa-book fa-3x mb-3"></i>
                                <p>Belum ada jurnal harian</p>
                                <small class="text-muted">Jurnal akan muncul di sini setelah siswa mengisi jurnal harian</small>
                            <?php endif; ?>
                        </td>
                    </tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>

        
        <div class="d-block d-md-none">
            <?php $__empty_1 = true; $__currentLoopData = $jurnal; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $j): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
            <div class="card mb-3 border-start border-primary border-4">
                <div class="card-body py-3">
                    <div class="d-flex justify-content-between align-items-start mb-2">
                        <?php
                        $tanggal = \Carbon\Carbon::parse($j->tanggal);
                        $hariIndonesia = ['Minggu', 'Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat', 'Sabtu'];
                        $bulanIndonesia = ['', 'Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni', 'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember'];
                        ?>
                        <h6 class="fw-bold mb-1"><?php echo e($tanggal->day); ?> <?php echo e($bulanIndonesia[$tanggal->month]); ?> <?php echo e($tanggal->year); ?></h6>
                        <div class="d-flex align-items-center gap-2">
                            <small class="text-muted">#<?php echo e($jurnal->firstItem() + $index); ?></small>
                            <?php if($j->status_verifikasi == 'pending'): ?>
                                <span class="badge bg-warning text-dark">
                                    <i class="fas fa-clock"></i> Pending
                                </span>
                            <?php elseif($j->status_verifikasi == 'diterima'): ?>
                                <span class="badge bg-success">
                                    <i class="fas fa-check"></i> Diterima
                                </span>
                            <?php else: ?>
                                <span class="badge bg-danger">
                                    <i class="fas fa-times"></i> Ditolak
                                </span>
                            <?php endif; ?>
                        </div>
                    </div>

                    <div class="row mb-2">
                        <div class="col-12">
                            <small class="text-muted">Nama Siswa:</small><br>
                            <div>
                                <small class="fw-semibold"><?php echo e($j->user->siswa->nama ?? $j->user->name); ?></small><br>
                                <small class="text-muted"><?php echo e($j->user->email); ?></small>
                            </div>
                        </div>
                    </div>

                    <div class="row mb-2">
                        <div class="col-12">
                            <small class="text-muted">Perencanaan:</small><br>
                            <small class="fw-semibold"><?php echo e(\Str::limit($j->perencanaan_kegiatan, 100)); ?></small>
                        </div>
                    </div>

                    <div class="mt-3">
                        <div class="btn-group btn-group-sm w-100" role="group">
                            <a href="<?php echo e(route('pembimbing-sekolah.jurnal.show', $j->id)); ?>" class="btn btn-outline-primary">
                                <i class="fas fa-eye"></i> Detail
                            </a>
                        </div>
                    </div>
                </div>
            </div>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
            <div class="text-center text-muted py-5">
                <?php if(request()->hasAny(['status', 'nama_siswa', 'tanggal_dari', 'tanggal_sampai'])): ?>
                    <i class="fas fa-search fa-3x mb-3"></i>
                    <p>Tidak ditemukan jurnal dengan kriteria yang dipilih</p>
                    <a href="<?php echo e(route('pembimbing-sekolah.jurnal')); ?>" class="btn btn-primary">Reset Filter</a>
                <?php else: ?>
                    <i class="fas fa-book fa-3x mb-3"></i>
                    <p>Belum ada jurnal harian</p>
                    <small class="text-muted">Jurnal akan muncul di sini setelah siswa mengisi jurnal harian</small>
                <?php endif; ?>
            </div>
            <?php endif; ?>
        </div>
        
        <!-- Pagination -->
        <?php if($jurnal->lastPage() > 1): ?>
        <div class="d-flex justify-content-between align-items-center">
            <div>
                <nav aria-label="Page navigation">
                    <ul class="pagination pagination-sm mb-0">
                        <?php if($jurnal->onFirstPage()): ?>
                            <li class="page-item disabled">
                                <span class="page-link"><i class="fas fa-chevron-left"></i></span>
                            </li>
                        <?php else: ?>
                            <li class="page-item">
                                <a class="page-link" href="<?php echo e($jurnal->appends(request()->query())->previousPageUrl()); ?>">
                                    <i class="fas fa-chevron-left"></i>
                                </a>
                            </li>
                        <?php endif; ?>

                        <?php
                            $start = max($jurnal->currentPage() - 2, 1);
                            $end = min($start + 4, $jurnal->lastPage());
                            $start = max($end - 4, 1);
                        ?>

                        <?php if($start > 1): ?>
                            <li class="page-item">
                                <a class="page-link" href="<?php echo e($jurnal->appends(request()->query())->url(1)); ?>">1</a>
                            </li>
                            <?php if($start > 2): ?>
                                <li class="page-item disabled"><span class="page-link">...</span></li>
                            <?php endif; ?>
                        <?php endif; ?>

                        <?php for($i = $start; $i <= $end; $i++): ?>
                            <?php if($i == $jurnal->currentPage()): ?>
                                <li class="page-item active">
                                    <span class="page-link"><?php echo e($i); ?></span>
                                </li>
                            <?php else: ?>
                                <li class="page-item">
                                    <a class="page-link" href="<?php echo e($jurnal->appends(request()->query())->url($i)); ?>"><?php echo e($i); ?></a>
                                </li>
                            <?php endif; ?>
                        <?php endfor; ?>

                        <?php if($end < $jurnal->lastPage()): ?>
                            <?php if($end < $jurnal->lastPage() - 1): ?>
                                <li class="page-item disabled"><span class="page-link">...</span></li>
                            <?php endif; ?>
                            <li class="page-item">
                                <a class="page-link" href="<?php echo e($jurnal->appends(request()->query())->url($jurnal->lastPage())); ?>"><?php echo e($jurnal->lastPage()); ?></a>
                            </li>
                        <?php endif; ?>

                        <?php if($jurnal->hasMorePages()): ?>
                            <li class="page-item">
                                <a class="page-link" href="<?php echo e($jurnal->appends(request()->query())->nextPageUrl()); ?>">
                                    <i class="fas fa-chevron-right"></i>
                                </a>
                            </li>
                        <?php else: ?>
                            <li class="page-item disabled">
                                <span class="page-link"><i class="fas fa-chevron-right"></i></span>
                            </li>
                        <?php endif; ?>
                    </ul>
                </nav>
            </div>
            <div>
                <small class="text-muted">
                    Halaman <?php echo e($jurnal->currentPage()); ?> dari <?php echo e($jurnal->lastPage()); ?> 
                    <span class="mx-1">•</span>
                    <?php echo e(number_format($jurnal->total())); ?> total jurnal
                </small>
            </div>
        </div>
        <?php endif; ?>
    </div>
</div>

<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
<script>
    document.addEventListener('DOMContentLoaded', function() {
        // Auto submit form when select changes (optional)
        const selectElements = document.querySelectorAll('select[name="status"]');
        selectElements.forEach(select => {
            select.addEventListener('change', function() {
                // Optional: Auto submit on change
                // this.form.submit();
            });
        });

        // Search on Enter key press for nama_siswa field
        const searchInput = document.querySelector('input[name="nama_siswa"]');
        if (searchInput) {
            searchInput.addEventListener('keypress', function(e) {
                if (e.key === 'Enter') {
                    this.form.submit();
                }
            });
        }
    });
</script>
<?php $__env->stopPush(); ?>
<?php echo $__env->make('layouts.pembimbing-sekolah', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\laragon\www\presensi-magang\resources\views/pembimbing-sekolah/jurnal/index.blade.php ENDPATH**/ ?>