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

<div class="d-flex justify-content-between align-items-center mb-3">
    <p class="text-muted mb-0">Platform operator logins — separate from any hotel's own staff accounts.</p>
    <a href="<?= site_url('admin/admins/new') ?>" class="btn btn-primary btn-sm"><i class="bi bi-plus-lg me-1"></i>New Admin</a>
</div>

<div class="card">
    <div class="table-responsive">
        <table class="table mb-0 align-middle">
            <thead><tr><th>Name</th><th>Email</th><th>Role</th><th>Last Login</th><th>Status</th><th></th></tr></thead>
            <tbody>
            <?php foreach ($admins as $a): ?>
                <tr>
                    <td class="fw-semibold"><?= esc($a->full_name) ?></td>
                    <td class="text-muted"><?= esc($a->email) ?></td>
                    <td><span class="badge bg-light text-dark border"><?= esc(ucfirst(str_replace('_', ' ', $a->role))) ?></span></td>
                    <td class="text-muted small"><?= $a->last_login_at ? esc(date('d M Y, g:i a', strtotime($a->last_login_at))) : 'Never' ?></td>
                    <td><span class="badge bg-<?= $a->is_active ? 'success' : 'secondary' ?>"><?= $a->is_active ? 'Active' : 'Inactive' ?></span></td>
                    <td class="text-end">
                        <form action="<?= site_url('admin/admins/' . $a->id . '/toggle-active') ?>" method="post">
                            <?= csrf_field() ?>
                            <button type="submit" class="btn btn-sm btn-outline-secondary"><?= $a->is_active ? 'Deactivate' : 'Activate' ?></button>
                        </form>
                    </td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</div>

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