<?= $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;">Persetujuan KRS</h1>
</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; ?>

<?php if(session()->getFlashdata('error')) : ?>
    <div class="alert alert-danger" style="background-color: #fee2e2; color: #991b1b; padding: 1rem; border-radius: 6px; margin-bottom: 1rem; border: 1px solid #fecaca;">
        <?= session()->getFlashdata('error') ?>
    </div>
<?php endif; ?>

<div class="card glass">
    <div class="card-header">
        <h5 class="m-0">Daftar Mahasiswa Bimbingan - <?= esc($ta['nama_ta']) ?></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;">NIM / NAMA MAHASISWA</th>
                        <th style="padding: 1rem; text-align: left; color: #64748b; font-weight: 600; font-size: 0.875rem;">PROGRAM STUDI</th>
                        <th style="padding: 1rem; text-align: center; color: #64748b; font-weight: 600; font-size: 0.875rem;">STATUS KRS</th>
                        <th style="padding: 1rem; text-align: center; color: #64748b; font-weight: 600; font-size: 0.875rem;">TANGGAL PENGAJUAN</th>
                        <th style="padding: 1rem; text-align: center; color: #64748b; font-weight: 600; font-size: 0.875rem;">AKSI</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $i=1; foreach($krsList as $krs): ?>
                    <tr style="border-bottom: 1px solid #e2e8f0;">
                        <td style="padding: 1rem;"><?= $i++ ?></td>
                        <td style="padding: 1rem;">
                            <div style="font-weight: bold;"><?= esc($krs['nim']) ?></div>
                            <div style="color: #64748b; font-size: 0.875rem;"><?= esc($krs['nama_lengkap']) ?></div>
                        </td>
                        <td style="padding: 1rem;"><?= esc($krs['nama_prodi'] ?? '-') ?></td>
                        <td style="padding: 1rem; text-align: center;">
                            <?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; ?>
                        </td>
                        <td style="padding: 1rem; text-align: center;">
                            <?= date('d/m/Y H:i', strtotime($krs['updated_at'])) ?>
                        </td>
                        <td style="padding: 1rem; text-align: center;">
                            <a href="<?= base_url('persetujuan-krs/detail/'.$krs['id']) ?>" class="btn btn-sm btn-info" style="background-color: #38bdf8; border-color: #38bdf8; color: white;" title="Lihat & Proses KRS">
                                <i class='bx bx-search-alt'></i> Proses
                            </a>
                        </td>
                    </tr>
                    <?php endforeach; ?>
                    <?php if(empty($krsList)): ?>
                    <tr>
                        <td colspan="6" style="text-align: center; padding: 2rem; color: #64748b;">
                            Belum ada mahasiswa bimbingan yang mengajukan KRS.
                        </td>
                    </tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>

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