<?= $this->extend('layout/default') ?>

<?= $this->section('content') ?>

<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem;">
    <h1 class="page-title" style="margin-bottom: 0;">Detail Persetujuan KRS</h1>
    <a href="<?= base_url('persetujuan-krs') ?>" class="btn btn-secondary">
        <i class='bx bx-arrow-back'></i> Kembali
    </a>
</div>

<?php if(session()->getFlashdata('success')) : ?>
    <div class="alert alert-success" style="background-color: #d1fae5; color: #065f46; padding: 1rem; border-radius: 6px; margin-bottom: 1rem; border: 1px solid #a7f3d0;">
        <?= session()->getFlashdata('success') ?>
    </div>
<?php endif; ?>

<div class="row">
    <div class="col-md-4">
        <div class="card glass" style="margin-bottom: 20px;">
            <div class="card-body">
                <h5 style="margin-top:0; color: #1e293b; border-bottom: 1px solid #e2e8f0; padding-bottom: 10px; margin-bottom: 15px;">Informasi Mahasiswa</h5>
                
                <div style="margin-bottom: 15px;">
                    <label style="font-size: 0.8rem; color: #64748b; font-weight: 600; display: block;">NIM</label>
                    <div style="font-weight: 500;"><?= esc($krs['nim']) ?></div>
                </div>
                
                <div style="margin-bottom: 15px;">
                    <label style="font-size: 0.8rem; color: #64748b; font-weight: 600; display: block;">Nama Lengkap</label>
                    <div style="font-weight: 500;"><?= esc($krs['nama_lengkap']) ?></div>
                </div>
                
                <div style="margin-bottom: 15px;">
                    <label style="font-size: 0.8rem; color: #64748b; font-weight: 600; display: block;">Program Studi</label>
                    <div style="font-weight: 500;"><?= esc($krs['nama_prodi'] ?? '-') ?></div>
                </div>
                
                <div style="margin-bottom: 15px;">
                    <label style="font-size: 0.8rem; color: #64748b; font-weight: 600; display: block;">Total SKS Diambil</label>
                    <div style="font-weight: bold; color: #3b82f6; font-size: 1.1rem;"><?= $totalSks ?> SKS</div>
                </div>
                
                <div style="margin-bottom: 15px;">
                    <label style="font-size: 0.8rem; color: #64748b; font-weight: 600; display: block;">Status KRS</label>
                    <?php if($krs['status'] == 'Menunggu Persetujuan'): ?>
                        <span style="background-color: #fef3c7; color: #d97706; padding: 4px 8px; border-radius: 4px; font-size: 12px; font-weight: bold;">Menunggu Persetujuan</span>
                    <?php elseif($krs['status'] == 'Disetujui'): ?>
                        <span style="background-color: #d1fae5; color: #059669; padding: 4px 8px; border-radius: 4px; font-size: 12px; font-weight: bold;">Disetujui</span>
                    <?php else: ?>
                        <span style="background-color: #fee2e2; color: #dc2626; padding: 4px 8px; border-radius: 4px; font-size: 12px; font-weight: bold;">Ditolak</span>
                    <?php endif; ?>
                </div>
                
                <?php if($krs['catatan']): ?>
                <div style="margin-bottom: 15px;">
                    <label style="font-size: 0.8rem; color: #64748b; font-weight: 600; display: block;">Catatan Sebelumnya</label>
                    <div style="background-color: #f8fafc; padding: 10px; border-radius: 4px; border: 1px solid #e2e8f0; font-size: 0.9rem;">
                        <?= nl2br(esc($krs['catatan'])) ?>
                    </div>
                </div>
                <?php endif; ?>
            </div>
        </div>
        
        <div class="card glass">
            <div class="card-body">
                <h5 style="margin-top:0; color: #1e293b; border-bottom: 1px solid #e2e8f0; padding-bottom: 10px; margin-bottom: 15px;">Tindakan Dosen PA</h5>
                
                <form action="<?= base_url('persetujuan-krs/proses/'.$krs['id']) ?>" method="POST">
                    <?= csrf_field() ?>
                    
                    <div class="form-group" style="margin-bottom: 15px;">
                        <label for="catatan" style="font-size: 0.85rem; font-weight: 600; color: #475569; display: block; margin-bottom: 5px;">Catatan (Opsional, wajib jika ditolak)</label>
                        <textarea name="catatan" id="catatan" rows="3" class="form-control" style="width: 100%; padding: 8px; border: 1px solid #cbd5e1; border-radius: 6px;"></textarea>
                    </div>
                    
                    <div style="display: flex; gap: 10px;">
                        <button type="submit" name="action" value="setujui" class="btn btn-success" style="flex: 1;" onclick="return confirm('Setujui KRS ini?')">
                            <i class='bx bx-check'></i> Setujui
                        </button>
                        <button type="submit" name="action" value="tolak" class="btn btn-danger" style="flex: 1;" onclick="return confirm('Tolak KRS ini?')">
                            <i class='bx bx-x'></i> Tolak
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    
    <div class="col-md-8">
        <div class="card glass">
            <div class="card-header">
                <h5 class="m-0">Mata Kuliah Yang Diambil</h5>
            </div>
            <div class="card-body" style="padding: 0;">
                <div class="table-responsive">
                    <table class="table" style="width: 100%; border-collapse: collapse; margin: 0;">
                        <thead>
                            <tr style="background-color: #f8fafc; border-bottom: 2px solid #e2e8f0;">
                                <th style="padding: 1rem; text-align: left; color: #64748b; font-weight: 600; font-size: 0.875rem;">NO</th>
                                <th style="padding: 1rem; text-align: left; color: #64748b; font-weight: 600; font-size: 0.875rem;">MATA KULIAH</th>
                                <th style="padding: 1rem; text-align: left; color: #64748b; font-weight: 600; font-size: 0.875rem;">KELAS</th>
                                <th style="padding: 1rem; text-align: center; color: #64748b; font-weight: 600; font-size: 0.875rem;">SKS</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php $i=1; foreach($pesertaKelas as $pk): ?>
                            <tr style="border-bottom: 1px solid #e2e8f0;">
                                <td style="padding: 1rem;"><?= $i++ ?></td>
                                <td style="padding: 1rem; font-weight: 500;"><?= esc($pk['nama_mata_kuliah']) ?></td>
                                <td style="padding: 1rem;"><?= esc($pk['nama_kelas_kuliah']) ?></td>
                                <td style="padding: 1rem; text-align: center; font-weight: bold;"><?= esc($pk['sks']) ?></td>
                            </tr>
                            <?php endforeach; ?>
                            <?php if(empty($pesertaKelas)): ?>
                            <tr>
                                <td colspan="4" style="text-align: center; padding: 2rem; color: #64748b;">
                                    Belum ada mata kuliah yang diambil.
                                </td>
                            </tr>
                            <?php endif; ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

<?= $this->endSection() ?>
