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

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

<div class="content-header">
    <div class="header-title">
        <h2>Kelola Dosen Pengajar Kelas</h2>
        <p>Mengatur penugasan dosen (Team Teaching) untuk kelas <?= esc($kelas['nama_kelas_kuliah']) ?> (<?= esc($kelas['nama_mata_kuliah']) ?>)</p>
    </div>
    <div class="header-actions">
        <a href="<?= base_url('kelas-perkuliahan') ?>" class="btn btn-secondary">
            <i class="fas fa-arrow-left"></i> Kembali
        </a>
    </div>
</div>

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

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

<div class="card" style="background: white; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); margin-bottom: 1.5rem; overflow: hidden;">
    <div class="card-header" style="background: #f8f9fa; padding: 15px 20px; border-bottom: 1px solid #eee;">
        <h3 style="margin: 0; font-size: 16px; font-weight: bold;">Tambah Dosen Pengajar</h3>
    </div>
    <div class="card-body" style="padding: 20px;">
        <form action="<?= base_url('kelas-perkuliahan/dosen/add') ?>" method="POST" class="form-inline" style="display: flex; gap: 10px; align-items: center; flex-wrap: wrap;">
            <?= csrf_field() ?>
            <input type="hidden" name="id_kelas_kuliah" value="<?= esc($kelas['id_kelas_kuliah_pddikti']) ?>">
            
            <select name="id_dosen" class="form-control" required style="flex: 1; min-width: 300px;">
                <option value="">-- Pilih Dosen Pengampu --</option>
                <?php foreach ($list_dosen as $d) : ?>
                    <option value="<?= esc($d['id_dosen_pddikti']) ?>"><?= esc($d['nidn'] ?? '-') ?> - <?= esc($d['nama_lengkap']) ?></option>
                <?php endforeach; ?>
            </select>
            
            <button type="submit" class="btn btn-primary" style="height: 38px;">
                <i class="fas fa-plus"></i> Tambah Dosen
            </button>
        </form>
    </div>
</div>

<div class="card" style="background: white; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.1);">
    <div class="card-header" style="background: #f8f9fa; padding: 15px 20px; border-bottom: 1px solid #eee;">
        <h3 style="margin: 0; font-size: 16px; font-weight: bold;">Daftar Dosen Pengajar (<?= count($dosenPengajar) ?> Dosen)</h3>
    </div>
    <div class="card-body" style="padding: 0;">
        <div class="table-responsive">
            <table class="table table-striped table-hover" style="margin-bottom: 0;">
                <thead style="background-color: #f8fafc;">
                    <tr>
                        <th style="padding: 12px 20px; border-bottom: 2px solid #e2e8f0; width: 5%;">No</th>
                        <th style="padding: 12px 20px; border-bottom: 2px solid #e2e8f0;">Nama Dosen</th>
                        <th style="padding: 12px 20px; border-bottom: 2px solid #e2e8f0; width: 15%;" class="text-center">Aksi</th>
                    </tr>
                </thead>
                <tbody>
                    <?php if (empty($dosenPengajar)) : ?>
                        <tr>
                            <td colspan="3" class="text-center" style="padding: 20px; color: #64748b;">Belum ada dosen yang ditugaskan ke kelas ini.</td>
                        </tr>
                    <?php else : ?>
                        <?php $no = 1; foreach ($dosenPengajar as $p) : ?>
                            <tr>
                                <td style="padding: 12px 20px; border-bottom: 1px solid #e2e8f0;"><?= $no++ ?></td>
                                <td style="padding: 12px 20px; border-bottom: 1px solid #e2e8f0;">
                                    <strong><?= esc($p['nama_dosen']) ?></strong>
                                </td>
                                <td style="padding: 12px 20px; border-bottom: 1px solid #e2e8f0;" class="text-center">
                                    <a href="<?= base_url('kelas-perkuliahan/dosen/delete/' . $p['id']) ?>" 
                                       class="btn btn-sm btn-danger" 
                                       onclick="return confirm('Apakah Anda yakin ingin menghapus dosen ini dari kelas?')"
                                       style="padding: 4px 8px; font-size: 12px;">
                                        <i class="fas fa-trash"></i> Hapus
                                    </a>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>

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