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

<?= $this->section('content') ?>
<div class="container-fluid px-4">
    <h1 class="mt-4"><?= $title ?></h1>
    <ol class="breadcrumb mb-4">
        <li class="breadcrumb-item"><a href="<?= base_url('admin') ?>">Dashboard</a></li>
        <li class="breadcrumb-item active">Struktur</li>
    </ol>

    <div class="card mb-4">
        <div class="card-header">
            <div class="row">
                <div class="col-md-6">
                    <i class="fas fa-sitemap me-1"></i> Data Struktur Organisasi
                </div>
                <div class="col-md-6 text-end">
                    <a href="<?= base_url('admin/struktur/tambah') ?>" class="btn btn-primary btn-sm">
                        <i class="fas fa-plus"></i> Tambah Personil
                    </a>
                </div>
            </div>
        </div>
        <div class="card-body">
            <?php if (session()->getFlashdata('success')) : ?>
                <div class="alert alert-success alert-dismissible fade show" role="alert">
                    <?= session()->getFlashdata('success') ?>
                    <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                </div>
            <?php endif; ?>

            <div class="table-responsive">
                <table class="table table-bordered table-hover" id="dataTable" width="100%" cellspacing="0">
                    <thead class="table-dark">
                        <tr>
                            <th>Urutan</th>
                            <th>Foto</th>
                            <th>Nama</th>
                            <th>Jabatan</th>
                            <th>Level</th>
                            <th>Aksi</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($struktur as $s) : ?>
                            <tr>
                                <td class="text-center"><?= $s['urutan'] ?></td>
                                <td class="text-center">
                                    <img src="<?= base_url('assets/img/team/' . $s['foto']) ?>" width="50" class="rounded shadow-sm">
                                </td>
                                <td><?= $s['nama'] ?></td>
                                <td><?= $s['jabatan'] ?></td>
                                <td>
                                    <?php 
                                        if($s['level'] == '1') echo '<span class="badge bg-danger">Kepala Sekolah</span>';
                                        elseif($s['level'] == '2') echo '<span class="badge bg-primary">Komite/TU</span>';
                                        else echo '<span class="badge bg-success">Wakasek/Staff</span>';
                                    ?>
                                </td>
                                <td>
                                    <a href="<?= base_url('admin/struktur/edit/' . $s['id_struktur']) ?>" class="btn btn-warning btn-sm"><i class="fas fa-edit"></i></a>
                                    <a href="<?= base_url('admin/struktur/hapus/' . $s['id_struktur']) ?>" class="btn btn-danger btn-sm" onclick="return confirm('Yakin ingin menghapus data ini?')"><i class="fas fa-trash"></i></a>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<?= $this->endSection() ?>