<?= $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 Supplier</h4>
        <a href="<?= base_url('admin/supplier/create') ?>" class="btn btn-sm btn-success">
            <i class="bi bi-plus-circle me-1"></i> Tambah Supplier
        </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 style="width: 40px;">#</th>
                        <th>Nama</th>
                        <th>Email</th>
                        <th>Kontak Person</th>
                        <th>Telepon</th>
                        <th>Alamat</th>
                        <th>Dibuat</th>
                        <th>Diubah</th>
                        <th style="width: 150px;">Aksi</th>
                    </tr>
                </thead>
                <tbody>
                    <?php if (!empty($suppliers)) : ?>
                        <?php foreach ($suppliers as $key => $s): ?>
                            <tr>
                                <td class="text-center text-muted">
                                    <?= $key + 1 ?>
                                </td>
                                <td><?= esc($s['nama']) ?></td>
                                <td><?= esc($s['email']) ?></td>
                                <td><?= esc($s['kontak_person']) ?></td>
                                <td><?= esc($s['telepon']) ?></td>
                                <td><?= esc($s['alamat']) ?></td>
                                <td class="text-muted"><?= date('d/m/Y H:i', strtotime($s['created_at'])) ?></td>
                                <td class="text-muted"><?= $s['diubah'] ? date('d/m/Y H:i', strtotime($s['diubah'])) : '-' ?></td>
                                <td class="text-center">
                                    <a href="<?= base_url('admin/supplier/edit/' . $s['id']) ?>" class="btn btn-warning btn-sm">
                                        <i class="bi bi-pencil-square me-1"></i> Edit
                                    </a>
                                    <a href="<?= base_url('admin/supplier/delete/' . $s['id']) ?>" class="btn btn-danger btn-sm" onclick="return confirm('Yakin hapus supplier ini?')">
                                        <i class="bi bi-trash-fill me-1"></i> Hapus
                                    </a>
                                </td>
                            </tr>
                        <?php endforeach ?>
                    <?php else : ?>
                        <tr>
                            <td colspan="8" class="text-center text-muted py-4">
                                <i class="bi bi-info-circle me-1"></i> Belum ada data supplier.
                            </td>
                        </tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>

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