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

<?php $__env->startSection('content'); ?>
<div class="card">
    <div class="card-header bg-white">
        <div class="d-flex justify-content-between align-items-center">
            <div>
                <h5 class="mb-0"><i class="fas fa-book me-2"></i>Detail Jurnal Harian</h5>
                <small class="text-muted">Verifikasi jurnal kegiatan magang siswa</small>
            </div>
            <a href="<?php echo e(route('pembimbing-magang.jurnal')); ?>" class="btn btn-outline-secondary btn-sm">
                <i class="fas fa-arrow-left me-1"></i>Kembali
            </a>
        </div>
    </div>
    
    <div class="card-body">
        <div class="row align-items-start">
            <!-- Kolom kiri -->
            <div class="col-md-8">
                <!-- Info Siswa (ikon dihilangkan, hanya nama) -->
                <div class="row mb-4">
                    <div class="col-sm-3">
                        <strong>Siswa:</strong>
                    </div>
                    <div class="col-sm-9">
                        <div>
                            <span class="fw-bold"><?php echo e($jurnal->user->siswa->nama_siswa ?? $jurnal->user->name); ?></span>
                        </div>
                    </div>
                </div>

                <div class="mb-4">
                    <div class="row mb-3">
                        <div class="col-sm-3">
                            <strong>Tanggal:</strong>
                        </div>
                        <div class="col-sm-9">
                            <?php
                            $tanggal = \Carbon\Carbon::parse($jurnal->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($hariIndonesia[$tanggal->dayOfWeek]); ?>, <?php echo e($tanggal->day); ?> <?php echo e($bulanIndonesia[$tanggal->month]); ?> <?php echo e($tanggal->year); ?></span>
                        </div>
                    </div>

                    <div class="row mb-3">
                        <div class="col-sm-3">
                            <strong>Status:</strong>
                        </div>
                        <div class="col-sm-9">
                            <?php if($jurnal->status_verifikasi == 'pending'): ?>
                                <span class="badge bg-warning text-dark fs-6">
                                    <i class="fas fa-clock"></i> Menunggu Verifikasi
                                </span>
                            <?php elseif($jurnal->status_verifikasi == 'diterima'): ?>
                                <span class="badge bg-success fs-6">
                                    <i class="fas fa-check"></i> Diterima
                                </span>
                            <?php else: ?>
                                <span class="badge bg-danger fs-6">
                                    <i class="fas fa-times"></i> Ditolak
                                </span>
                            <?php endif; ?>
                        </div>
                    </div>

                    

                    <div class="row mb-4">
                        <div class="col-sm-3">
                            <strong>Perencanaan Kegiatan:</strong>
                        </div>
                        <div class="col-sm-9">
                            <div class="bg-light p-3 rounded">
                                <?php echo e($jurnal->perencanaan_kegiatan); ?>

                            </div>
                        </div>
                    </div>

                    <div class="row mb-4">
                        <div class="col-sm-3">
                            <strong>Pelaksanaan Kegiatan:</strong>
                        </div>
                        <div class="col-sm-9">
                            <div class="bg-light p-3 rounded">
                                <?php echo e($jurnal->pelaksanaan_kegiatan); ?>

                            </div>
                        </div>
                    </div>

                    <?php if($jurnal->catatan_instruktur): ?>
                    <div class="row mb-4">
                        <div class="col-sm-3">
                            <strong>Catatan Instruktur:</strong>
                        </div>
                        <div class="col-sm-9">
                            <div class="bg-info bg-opacity-10 border border-info p-3 rounded">
                                <i class="fas fa-comment-alt me-2 text-info"></i>
                                <?php echo e($jurnal->catatan_instruktur); ?>

                            </div>
                        </div>
                    </div>
                    <?php endif; ?>
                </div>

                <!-- Tombol Aksi Verifikasi: jika pending tampil Terima/Tolak, kalau sudah diverifikasi tampil Edit Verifikasi -->
                <?php if($jurnal->status_verifikasi == 'pending'): ?>
                <div class="d-flex gap-2">
                    <button type="button" class="btn btn-success" 
                            onclick="verifikasiJurnal(<?php echo e($jurnal->id); ?>, 'diterima')">
                        <i class="fas fa-check me-1"></i>Terima Jurnal
                    </button>
                    <button type="button" class="btn btn-danger" 
                            onclick="verifikasiJurnal(<?php echo e($jurnal->id); ?>, 'ditolak')">
                        <i class="fas fa-times me-1"></i>Tolak Jurnal
                    </button>
                </div>
                <?php else: ?>
                <div class="d-flex gap-2">
                    <button type="button" class="btn btn-warning" 
                            onclick="editVerifikasi(<?php echo e($jurnal->id); ?>, '<?php echo e($jurnal->status_verifikasi); ?>', '<?php echo e(addslashes($jurnal->catatan_instruktur)); ?>')">
                        <i class="fas fa-edit me-1"></i>Edit Verifikasi
                    </button>
                </div>
                <?php endif; ?>
            </div>

            <!-- Kolom kanan -->
            <div class="col-md-4">
                <div class="card bg-light h-100">
                    <div class="card-body">
                        <h6 class="card-title"><i class="fas fa-info-circle me-2"></i>Informasi Verifikasi</h6>
                        <ul class="list-unstyled mb-0">
                            <?php if($jurnal->status_verifikasi == 'pending'): ?>
                                <li><i class="fas fa-clock text-warning me-2"></i>Jurnal menunggu verifikasi Anda</li>
                                <li><i class="fas fa-check-circle text-success me-2"></i>Klik "Terima" untuk menyetujui</li>
                                <li><i class="fas fa-times-circle text-danger me-2"></i>Klik "Tolak" untuk menolak</li>
                            <?php elseif($jurnal->status_verifikasi == 'diterima'): ?>
                                <li><i class="fas fa-check text-success me-2"></i>Jurnal telah Anda terima</li>
                                <li><i class="fas fa-calendar-check text-info me-2"></i>Diverifikasi: <?php echo e($jurnal->updated_at->format('d/m/Y')); ?></li>
                            <?php else: ?>
                                <li><i class="fas fa-times text-danger me-2"></i>Jurnal telah Anda tolak</li>
                                <li><i class="fas fa-calendar-times text-warning me-2"></i>Ditolak: <?php echo e($jurnal->updated_at->format('d/m/Y')); ?></li>
                                <?php if($jurnal->catatan_instruktur): ?>
                                    <li><i class="fas fa-comment text-info me-2"></i>Catatan telah diberikan</li>
                                <?php endif; ?>
                            <?php endif; ?>
                        </ul>

                        <hr>

                        <div class="d-grid gap-2">
                            <a href="<?php echo e(route('pembimbing-magang.siswa')); ?>" class="btn btn-outline-secondary btn-sm">
                                <i class="fas fa-users me-1"></i>Lihat Semua Siswa
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- Modal Verifikasi -->
<div class="modal fade" id="verifikasiModal" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="verifikasiModalLabel">Verifikasi Jurnal</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>
            <form id="verifikasiForm" method="POST">
                <?php echo csrf_field(); ?>
                <div class="modal-body">
                    <div class="mb-3">
                        <label for="status_verifikasi" class="form-label">Status Verifikasi</label>
                        <select class="form-select" name="status_verifikasi" id="status_verifikasi" required>
                            <option value="">Pilih Status</option>
                            <option value="diterima">Diterima</option>
                            <option value="ditolak">Ditolak</option>
                        </select>
                    </div>
                    <div class="mb-3">
                        <label for="catatan_instruktur" class="form-label">Catatan Instruktur</label>
                        <textarea class="form-control" name="catatan_instruktur" id="catatan_instruktur" 
                                  rows="4" placeholder="Berikan catatan atau feedback untuk siswa..."></textarea>
                        <small class="text-muted">Catatan wajib diisi jika jurnal ditolak</small>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Batal</button>
                    <button type="submit" class="btn btn-primary">Simpan Verifikasi</button>
                </div>
            </form>
        </div>
    </div>
</div>

<style>
.card-body p {
    line-height: 1.6;
    color: #495057;
}

.badge {
    font-size: 0.75rem;
    padding: 0.35em 0.65em;
}
</style>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
<script>
/**
 * Buka modal untuk menerima/menolak jurnal (dipanggil dari tombol Terima/Tolak)
 * Menggunakan onchange assignment agar listener tidak bertumpuk.
 */
function verifikasiJurnal(jurnalId, status) {
    const modalEl = document.getElementById('verifikasiModal');
    const modal = new bootstrap.Modal(modalEl);
    const form = document.getElementById('verifikasiForm');
    const statusSelect = document.getElementById('status_verifikasi');
    const catatanField = document.getElementById('catatan_instruktur');

    // Set form action
    form.action = `/pembimbing-magang/jurnal/${jurnalId}/verifikasi`;

    // Set status & clear catatan
    statusSelect.value = status;
    catatanField.value = '';

    // Set onchange (replace previous handler)
    statusSelect.onchange = function() {
        if (this.value === 'ditolak') {
            catatanField.required = true;
            catatanField.parentElement.querySelector('small').style.color = '#e74a3b';
        } else {
            catatanField.required = false;
            catatanField.parentElement.querySelector('small').style.color = '#6c757d';
        }
    };

    // Trigger handler dan tampilkan modal
    statusSelect.onchange();
    modal.show();
}

/**
 * Buka modal untuk mengedit verifikasi yang sudah ada.
 * currentStatus: 'diterima' | 'ditolak'
 * currentCatatan: (string) catatan yang sudah ada (di-passed dari blade dengan addslashes)
 */
function editVerifikasi(jurnalId, currentStatus, currentCatatan) {
    const modalEl = document.getElementById('verifikasiModal');
    const modal = new bootstrap.Modal(modalEl);
    const form = document.getElementById('verifikasiForm');
    const statusSelect = document.getElementById('status_verifikasi');
    const catatanField = document.getElementById('catatan_instruktur');

    // Set form action
    form.action = `/pembimbing-magang/jurnal/${jurnalId}/verifikasi`;

    // Isi nilai sekarang (catatan bisa kosong)
    statusSelect.value = currentStatus || '';
    catatanField.value = currentCatatan || '';

    // Set onchange (replace previous)
    statusSelect.onchange = function() {
        if (this.value === 'ditolak') {
            catatanField.required = true;
            catatanField.parentElement.querySelector('small').style.color = '#e74a3b';
        } else {
            catatanField.required = false;
            catatanField.parentElement.querySelector('small').style.color = '#6c757d';
        }
    };

    // Trigger handler dan tampilkan modal
    statusSelect.onchange();
    modal.show();
}

// Validasi form sebelum submit
document.getElementById('verifikasiForm').addEventListener('submit', function(e) {
    const status = document.getElementById('status_verifikasi').value;
    const catatan = document.getElementById('catatan_instruktur').value;

    if (status === 'ditolak' && !catatan.trim()) {
        e.preventDefault();
        alert('Catatan wajib diisi jika jurnal ditolak!');
        document.getElementById('catatan_instruktur').focus();
    }
});
</script>
<?php $__env->stopSection(); ?>

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