<?= $this->extend('layout/admin') ?>
<?= $this->section('content') ?>

<div class="card shadow-sm">
    <div class="card-header d-flex justify-content-between align-items-center bg-primary text-white">
        <b>Daftar Pembayaran PPDB</b>

        <a href="<?= site_url('ppdb/payment/add') ?>" 
           class="btn btn-success btn-sm text-white fw-bold shadow-sm">
            <i class="fas fa-plus-circle me-1"></i> Tambah Pembayaran
        </a>
    </div>

    <div class="card-body">
        <table id="dt_payment" class="table table-bordered table-striped w-100">
            <thead class="table-dark">
                <tr>
                    <th>No</th>
                    <th>No Daftar</th>
                    <th>Nama Siswa</th>
                    <th>Jumlah Bayar</th>
                    <th>Metode</th>
                    <th>Status</th>
                    <th>Tanggal Bayar</th>
                    <th>Aksi</th>
                </tr>
            </thead>
        </table>
    </div>
</div>

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

<?= $this->section('scripts') ?>
<script>
$(function () {
    $('#dt_payment').DataTable({
        ajax: {
            url: "<?= site_url('ppdb/payment/data') ?>",
            type: "GET"
        },

        columns: [
            { data: "id", render: (d, t, r, m) => m.row + 1 },
            { data: "reg_no" },
            { data: "student_name" },
            { data: "amount", render: d => new Intl.NumberFormat('id-ID').format(d) },
            { data: "method" },
            { data: "status" },
            { data: "payment_date" },
            {
                data: "id",
                render: function (id) {
                    return `
                    <div class="btn-group">
                        <a href="<?= site_url('ppdb/payment/detail') ?>/${id}" 
                           class="btn btn-sm btn-info">Detail</a>

                        <a href="<?= site_url('ppdb/payment/edit') ?>/${id}" 
                           class="btn btn-sm btn-warning text-white">Edit</a>

                        <a href="<?= site_url('ppdb/payment/delete') ?>/${id}" 
                           onclick="return confirm('Yakin hapus pembayaran ini?')"
                           class="btn btn-sm btn-danger">Hapus</a>
                    </div>`;
                }
            }
        ]
    });
});
</script>
<?= $this->endSection() ?>
