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

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

<div class="card-header" style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem;">
    <h1 class="page-title" style="margin-bottom: 0;">Data Master Program Studi</h1>
    <div>
        <a href="<?= base_url('prodi/sync-pddikti') ?>" class="btn btn-warning" onclick="return confirm('Proses ini akan menarik data Program Studi dari PDDIKTI. Lanjutkan?');">
            <i class='bx bx-refresh'></i> Sinkronisasi PDDIKTI
        </a>
        <a href="<?= base_url('prodi/create') ?>" class="btn btn-primary" style="margin-left: 10px;">
            <i class='bx bx-plus'></i> Tambah Prodi
        </a>
    </div>
</div>

<?php if(session()->getFlashdata('success')) : ?>
    <div class="alert alert-success">
        <?= session()->getFlashdata('success') ?>
    </div>
<?php endif; ?>

<div class="table-container">
    <table class="table">
        <thead>
            <tr>
                <th width="5%">No</th>
                <th>Fakultas</th>
                <th>Kode</th>
                <th>Nama Program Studi</th>
                <th>Jenjang</th>
                <th>Akreditasi</th>
                <th width="15%" style="text-align: center;">Aksi</th>
            </tr>
        </thead>
        <tbody>
            <?php if(empty($prodi)) : ?>
                <tr>
                    <td colspan="7" style="text-align: center; color: var(--text-muted);">Belum ada data Program Studi.</td>
                </tr>
            <?php else : ?>
                <?php $i = 1; foreach($prodi as $p) : ?>
                    <tr>
                        <td><?= $i++ ?></td>
                        <td><?= esc($p['nama_fakultas']) ?></td>
                        <td><strong><?= esc($p['kode_prodi']) ?></strong></td>
                        <td><?= esc($p['nama_prodi']) ?></td>
                        <td><?= esc($p['jenjang']) ?></td>
                        <td>
                            <?php if(!empty($p['akreditasi'])): ?>
                                <span style="background: rgba(16, 185, 129, 0.1); color: #059669; padding: 0.2rem 0.5rem; border-radius: 0.25rem; font-size: 0.8rem; font-weight: 600;">
                                    <?= esc($p['akreditasi']) ?>
                                </span>
                            <?php else: ?>
                                -
                            <?php endif; ?>
                        </td>
                        <td style="text-align: center;">
                            <a href="<?= base_url('prodi/edit/'.$p['id']) ?>" class="btn btn-sm btn-warning" title="Edit">
                                <i class='bx bx-edit-alt'></i>
                            </a>
                            <form action="<?= base_url('prodi/delete/'.$p['id']) ?>" method="post" style="display: inline;" onsubmit="return confirm('Apakah Anda yakin ingin menghapus data ini?');">
                                <?= csrf_field() ?>
                                <button type="submit" class="btn btn-sm btn-danger" title="Hapus">
                                    <i class='bx bx-trash'></i>
                                </button>
                            </form>
                        </td>
                    </tr>
                <?php endforeach; ?>
            <?php endif; ?>
        </tbody>
    </table>
</div>

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