<?php $title = 'Post Categories'; ?>
<div class="d-sm-flex align-items-center justify-content-between mb-4">
    <h1 class="h3 mb-0 text-white font-weight-bold"><i class="fas fa-tags mr-2"></i>Post Categories</h1>
    <?php if (isset($_SESSION['user_role']) && $_SESSION['user_role'] === 'admin'): ?>
    <a href="<?= $baseUrl ?>/post-categories/create" class="glass-btn glass-btn-primary"><i class="fas fa-plus mr-1"></i>New Category</a>
    <?php endif; ?>
</div>
<div class="glass-card">
    <div class="glass-table">
        <table class="table">
            <thead><tr><th>Name</th><th>Slug</th><th>Description</th><th>Posts</th><th>Order</th><th>Status</th><th>Actions</th></tr></thead>
            <tbody>
                <?php if (!empty($categories)): ?>
                    <?php foreach ($categories as $cat): ?>
                    <tr>
                        <td class="font-weight-bold text-white"><?= htmlspecialchars($cat->name) ?></td>
                        <td><code><?= htmlspecialchars($cat->slug) ?></code></td>
                        <td style="color: rgba(255,255,255,0.6);"><?= htmlspecialchars($cat->description ?? '-') ?></td>
                        <td><span class="glass-badge"><?= $cat->post_count ?? 0 ?></span></td>
                        <td style="color: rgba(255,255,255,0.5);"><?= $cat->sort_order ?? 0 ?></td>
                        <td>
                            <span class="glass-badge" style="background: <?= $cat->is_active ? 'rgba(28,200,138,0.2)' : 'rgba(255,255,255,0.1)' ?>; color: <?= $cat->is_active ? '#1cc88a' : 'rgba(255,255,255,0.5)' ?>;">
                                <?= $cat->is_active ? 'Active' : 'Inactive' ?>
                            </span>
                        </td>
                        <td>
                            <a href="<?= $baseUrl ?>/post-categories/<?= $cat->id ?>/edit" class="btn btn-sm btn-primary"><i class="fas fa-edit"></i></a>
                            <form method="POST" action="<?= $baseUrl ?>/post-categories/<?= $cat->id ?>/delete" style="display:inline;" onsubmit="return confirm('Delete category &quot;<?= htmlspecialchars($cat->name) ?>&quot;? Posts in this category will become uncategorized.');">
                                <button type="submit" class="btn btn-sm btn-danger"><i class="fas fa-trash"></i></button>
                            </form>
                        </td>
                    </tr>
                    <?php endforeach; ?>
                <?php else: ?>
                <tr><td colspan="7" class="text-center" style="color: rgba(255,255,255,0.5);">No categories yet</td></tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>
