<?= $this->extend('layout/admin') ?>
<?= $this->section('title') ?>Manage Users<?= $this->endSection() ?>

<?= $this->section('content') ?>
<div class="page-header">
    <h1 style="font-size: 1.5rem; font-weight: 700;">Users Directory</h1>
</div>

<div class="table-wrapper">
    <table>
        <thead>
            <tr>
                <th>ID</th>
                <th>Username</th>
                <th>Email</th>
                <th>Role</th>
                <th>Status</th>
                <th>Action</th>
            </tr>
        </thead>
        <tbody>
            <?php foreach($users as $user): ?>
            <tr>
                <td>#<?= esc($user->id) ?></td>
                <td style="font-weight: 600;"><?= esc($user->username) ?></td>
                <td><?= esc($user->email) ?></td>
                <td>
                    <span style="font-size: 0.75rem; padding: 0.1rem 0.4rem; background: #e5e7eb; border-radius: 4px;"><?= strtoupper(esc($user->role)) ?></span>
                </td>
                <td>
                    <span class="status-badge status-<?= esc($user->status) ?>"><?= ucfirst(esc($user->status)) ?></span>
                </td>
                <td>
                    <?php if($user->id !== session()->get('id')): ?>
                        <a href="<?= base_url('admin/users/toggle/' . $user->id) ?>" class="btn btn-outline" style="font-size: 0.75rem; padding: 0.25rem 0.5rem; border-color: <?= $user->status == 'active' ? 'var(--error)' : 'var(--success)' ?>;">
                            <?= $user->status == 'active' ? 'Suspend' : 'Activate' ?>
                        </a>
                    <?php else: ?>
                        <span style="color: var(--text-muted); font-size: 0.75rem;">(You)</span>
                    <?php endif; ?>
                </td>
            </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
</div>
<?= $this->endSection() ?>
