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

<div class="container mt-4">
    <div class="d-flex justify-content-between align-items-center mb-3">
        <h4 class="text-primary mb-0">Data Customers</h4>
        <a href="<?= base_url('admin/customer/create') ?>" class="btn btn-sm btn-success">
            <i class="fas fa-plus-circle me-1"></i> Tambah
        </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 shadow-sm rounded">
        <div class="card-body table-responsive">
            <table class="table table-bordered table-hover table-sm align-middle">
                <thead class="table-light text-center">
                    <tr>
                        <th width="50">#</th>
                        <th>Nama</th>
                        <th>Telepon</th>
                        <th>Email</th>
                        <th>Alamat</th>
                        <th width="150">Aksi</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($customers as $i => $c): ?>
                    <tr>
                        <td class="text-center"><?= $i + 1 ?></td>
                        <td><?= esc($c['nama']) ?></td>
                        <td><?= esc($c['telepon']) ?></td>
                        <td><?= esc($c['email']) ?></td>
                        <td><?= esc($c['alamat']) ?></td>
                        <td class="text-center">
                            <a href="<?= base_url('admin/customer/edit/' . $c['id']) ?>" class="btn btn-warning btn-sm">
                                <i class="fas fa-edit"></i> Edit
                            </a>
                            <a href="<?= base_url('admin/customer/delete/' . $c['id']) ?>" class="btn btn-danger btn-sm" onclick="return confirm('Hapus customer ini?')">
                                <i class="fas fa-trash-alt"></i> Hapus
                            </a>
                        </td>
                    </tr>
                    <?php endforeach ?>
                </tbody>
            </table>
        </div>
    </div>
</div>

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