<?= $this->extend('layouts/main') ?>
<?= $this->section('content') ?>

<div class="container-fluid py-4">
    <div class="d-flex justify-content-between align-items-center mb-3 flex-wrap gap-2">
        <h4 class="mb-0 text-primary">🧾 Daftar Pajak</h4>
        <a href="<?= base_url('admin/setting/tax/create') ?>" class="btn btn-success shadow-sm">
            <i class="bi bi-plus-circle"></i> Tambah Pajak
        </a>
    </div>

    <?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="card border-0 shadow-sm">
        <div class="card-body table-responsive p-0">
            <table class="table table-hover align-middle mb-0">
                <thead class="table-light text-center">
                    <tr>
                        <th style="width:5%">#</th>
                        <th>Nama Pajak</th>
                        <th>Persentase</th>
                        <th>Status</th>
                        <th style="width:20%">Aksi</th>
                    </tr>
                </thead>
                <tbody>
                    <?php if (!empty($taxes)): ?>
                        <?php $no = 1; foreach ($taxes as $t): ?>
                        <tr class="text-center">
                            <td><?= $no++ ?></td>
                            <td class="text-start"><?= esc($t['nama']) ?></td>
                            <td><?= esc($t['persen']) ?>%</td>
                            <td>
                                <?php if ($t['aktif']): ?>
                                    <span class="badge bg-success">Aktif</span>
                                <?php else: ?>
                                    <span class="badge bg-secondary">Nonaktif</span>
                                <?php endif ?>
                            </td>
                            <td>
                                <div class="d-flex justify-content-center gap-2 flex-wrap">
                                    <a href="<?= base_url('admin/setting/tax/edit/' . $t['id']) ?>" class="btn btn-warning btn-sm">
                                        <i class="bi bi-pencil-square"></i> Edit
                                    </a>
                                    <a href="<?= base_url('admin/setting/tax/toggle/' . $t['id']) ?>" class="btn btn-outline-secondary btn-sm">
                                        <?= $t['aktif'] ? 'Nonaktifkan' : 'Aktifkan' ?>
                                    </a>
                                </div>
                            </td>
                        </tr>
                        <?php endforeach ?>
                    <?php else: ?>
                        <tr>
                            <td colspan="5" class="text-center text-muted py-4">
                                <i class="bi bi-exclamation-circle fs-4"></i><br>
                                Belum ada data pajak.
                            </td>
                        </tr>
                    <?php endif ?>
                </tbody>
            </table>
        </div>
    </div>
</div>

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