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

<?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 Harian Saya</h5>
                <small class="text-muted">Catat kegiatan harian Anda selama masa magang</small>
            </div>
            <div class="col-12 col-md-6 text-md-end">
                <button class="btn btn-primary w-100 w-md-auto" data-bs-toggle="modal" data-bs-target="#tambahJurnalModal">
                    <i class="fas fa-plus me-2"></i>Tambah Jurnal
                </button>
            </div>
        </div>

        <!-- Form Filter (diubah: pakai tanggal mulai & akhir) -->
        <form method="GET" action="<?php echo e(route('jurnal')); ?>">
            <div class="row g-3 align-items-end">
                <div class="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-md-3">
                    <label class="form-label">Tanggal Mulai</label>
                    <input type="date" name="start_date" class="form-control" value="<?php echo e(request('start_date')); ?>">
                </div>

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

                <div class="col-md-3">
                    <div class="btn-group w-100" role="group">
                        <button type="submit" class="btn btn-primary">
                            <i class="fas fa-search"></i>
                        </button>
                        <?php if(request()->hasAny(['status', 'start_date', 'end_date'])): ?>
                            <a href="<?php echo e(route('jurnal')); ?>" class="btn btn-outline-secondary">
                                <i class="fas fa-times"></i>
                            </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 class="text-center">Status</th>
                        <th width="35%" class="text-center">Perencanaan</th>
                        <th width="35%" class="text-center">Pelaksanaan</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">
                            <?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">
                            <span class="d-inline-block text-truncate" style="max-width: 200px;" title="<?php echo e($j->pelaksanaan_kegiatan); ?>">
                                <?php echo e(\Str::limit($j->pelaksanaan_kegiatan, 80)); ?>

                            </span>
                        </td>
                        <td class="text-center">
                            <div class="btn-group text-center" role="group">
                                <a href="<?php echo e(route('jurnal.detail', $j->id)); ?>" class="btn btn-sm btn-info" title="Detail">
                                    <i class="fas fa-eye"></i>
                                </a>

                                <?php if($j->status_verifikasi == 'pending' || $j->status_verifikasi == 'ditolak'): ?>
                                <button class="btn btn-sm btn-warning" 
                                    onclick="editJurnal(<?php echo e($j->id); ?>, '<?php echo e($j->tanggal); ?>', '<?php echo e(addslashes($j->perencanaan_kegiatan)); ?>', '<?php echo e(addslashes($j->pelaksanaan_kegiatan)); ?>')" 
                                    title="Edit">
                                    <i class="fas fa-edit"></i>
                                </button>
                                <?php endif; ?>

                                <button class="btn btn-sm btn-danger" onclick="hapusJurnal(<?php echo e($j->id); ?>)" title="Hapus">
                                    <i class="fas fa-trash"></i>
                                </button>
                            </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', 'start_date', 'end_date'])): ?>
                                <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('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>
                                <button type="button" class="btn btn-success" data-bs-toggle="modal" data-bs-target="#tambahJurnalModal">
                                    <i class="fas fa-plus me-2"></i>Buat Jurnal Pertama
                                </button>
                            <?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">Perencanaan:</small><br>
                            <small class="fw-semibold"><?php echo e(\Str::limit($j->perencanaan_kegiatan, 100)); ?></small>
                        </div>
                    </div>

                    <div class="row mb-2">
                        <div class="col-12">
                            <small class="text-muted">Pelaksanaan:</small><br>
                            <small class="fw-semibold"><?php echo e(\Str::limit($j->pelaksanaan_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('jurnal.detail', $j->id)); ?>" class="btn btn-outline-primary">
                                <i class="fas fa-eye"></i> Detail
                            </a>
                            
                            <?php if($j->status_verifikasi == 'pending' || $j->status_verifikasi == 'ditolak'): ?>
                            <button type="button" class="btn btn-outline-warning" onclick="editJurnal(<?php echo e($j->id); ?>, '<?php echo e(\Carbon\Carbon::parse($j->tanggal)->format('Y-m-d')); ?>', '<?php echo e(addslashes($j->perencanaan_kegiatan)); ?>', '<?php echo e(addslashes($j->pelaksanaan_kegiatan)); ?>')">
                                <i class="fas fa-edit"></i> Edit
                            </button>
                            <?php endif; ?>
                            
                            <button type="button" class="btn btn-outline-danger" onclick="hapusJurnal(<?php echo e($j->id); ?>)">
                                <i class="fas fa-trash"></i>
                            </button>
                        </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', 'start_date', 'end_date'])): ?>
                    <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('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>
                    <button type="button" class="btn btn-success" data-bs-toggle="modal" data-bs-target="#tambahJurnalModal">
                        <i class="fas fa-plus me-2"></i>Buat Jurnal Pertama
                    </button>
                <?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 echo $__env->make('siswa.jurnal.tambah', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
<?php echo $__env->make('siswa.jurnal.edit', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
<?php echo $__env->make('siswa.jurnal.hapus', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
<?php echo $__env->make('siswa.jurnal.script', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.siswa', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\laragon\www\presensi-magang\resources\views/siswa/jurnal/index.blade.php ENDPATH**/ ?>