<?php include __DIR__ . '/../header.php'; ?>

<div class="container py-4">
    <div class="row">
        <div class="col-md-5 mb-4">
            <div class="card shadow border-0 rounded-4">
                <div class="card-header bg-white py-3">
                    <h5 class="m-0 fw-bold">Add New Category</h5>
                </div>
                <div class="card-body p-4">
                    <form action="/admin/categories/add" method="POST">
                        <div class="mb-3">
                            <label for="name" class="form-label fw-medium">Category Name</label>
                            <input type="text" class="form-control" id="name" name="name" placeholder="e.g. Games, Social Media" required>
                        </div>
                        <div class="d-grid">
                            <button type="submit" class="btn btn-primary rounded-pill py-2">Create Category</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>

        <div class="col-md-7">
            <div class="card shadow border-0 rounded-4">
                <div class="card-header bg-white py-3">
                    <h5 class="m-0 fw-bold">All Categories</h5>
                </div>
                <div class="card-body p-0">
                    <div class="table-responsive">
                        <table class="table table-hover mb-0">
                            <thead class="table-light">
                                <tr>
                                    <th class="ps-4">Name</th>
                                    <th>Slug</th>
                                    <th class="text-end pe-4">Actions</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php foreach ($categories as $cat): ?>
                                    <tr>
                                        <td class="ps-4 align-middle fw-medium"><?php echo $cat['name']; ?></td>
                                        <td class="align-middle text-muted"><?php echo $cat['slug']; ?></td>
                                        <td class="text-end pe-4 align-middle">
                                            <a href="/admin/categories/delete/<?php echo $cat['id']; ?>" class="btn btn-outline-danger btn-sm rounded-pill px-3" onclick="return confirm('Are you sure you want to delete this category?')">
                                                <i class="bi bi-trash"></i> Delete
                                            </a>
                                        </td>
                                    </tr>
                                <?php endforeach; ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<?php include __DIR__ . '/../footer.php'; ?>
