<div class="table-responsive">
    <table class="table table-hover align-middle rounded shadow-sm border">
        <thead class="table-light text-center">
            <tr class="align-middle">
                <th style="width: 40px;">#</th>
                <th>Kode</th>
                <th>Nama</th>
                <th>Kategori</th>
                <th>Unit</th>
                <th>Harga</th>
                <th>Diskon (%)</th>
                <th>Total Harga</th>
                <th>Stok</th>
                <th>Gudang</th>
                <th>Status</th>
                <th class="text-center">Aksi</th>
            </tr>
        </thead>
        <tbody>
            <?php if (empty($items)): ?>
                <tr>
                    <td colspan="11" class="text-center text-muted py-4">Data tidak ditemukan.</td>
                </tr>
            <?php else: ?>
                <?php foreach($items as $key => $item): ?>
                    <tr>
                        <td class="text-center"><?= $key + 1 ?></td>
                        <td><?= esc($item['barcode']) ?></td>
                        <td><?= esc($item['nama']) ?></td>
                        <td><?= esc($item['kategori']) ?></td>
                        <td><?= esc($item['unit']) ?></td>
                        <td>Rp<?= number_format($item['harga'], 0, ',', '.') ?></td>
                        <td class="text-center"><?= esc($item['diskon'] ?? 0) ?></td> 
                        <td>Rp<?= number_format($item['total_harga'], 0, ',', '.') ?></td>
                        <td><?= esc($item['stok']) ?></td>
                        <td><?= esc($item['gudang']) ?></td>
                        <td>
                            <?php if ($item['is_active']): ?>
                                <span class="badge bg-success bg-opacity-75">Aktif</span>
                            <?php else: ?>
                                <span class="badge bg-secondary bg-opacity-75">Nonaktif</span>
                            <?php endif; ?>
                        </td>
                        <td class="text-center">
                            <div class="btn-group btn-group-sm" role="group">
                                <a href="<?= base_url('admin/item/edit/' . $item['id']) ?>" class="btn btn-outline-warning" title="Edit">
                                    <i class="fas fa-edit"></i>
                                </a>
                                <?php if ($item['is_active']): ?>
                                    <a href="<?= base_url('admin/item/disable/' . $item['id']) ?>"
                                       class="btn btn-outline-danger"
                                       onclick="return confirm('Item ini akan dinonaktifkan dan tidak akan muncul di daftar transaksi. Lanjutkan?')"
                                       title="Nonaktifkan">
                                        <i class="fas fa-ban"></i>
                                    </a>
                                <?php else: ?>
                                    <a href="<?= base_url('admin/item/enable/' . $item['id']) ?>"
                                       class="btn btn-outline-success"
                                       onclick="return confirm('Item ini akan diaktifkan kembali dan muncul di daftar transaksi. Lanjutkan?')"
                                       title="Aktifkan">
                                        <i class="fas fa-check-circle"></i>
                                    </a>
                                <?php endif; ?>
                            </div>
                        </td>
                    </tr>
                <?php endforeach ?>
            <?php endif; ?>
        </tbody>
    </table>
</div>
