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

<?= $this->section('content') ?>

<div>
    <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 40px;">
        <div>
            <h1>Media Gallery</h1>
            <p style="color: var(--text-muted);">Manage your image and video gallery items.</p>
        </div>
        <a href="<?= base_url('admin/gallery_add') ?>" class="btn btn-primary"><i class="bi bi-plus-lg"></i> Add New Media</a>
    </div>

    <div class="admin-card">
        <table class="admin-table">
            <thead>
                <tr>
                    <th>Media</th>
                    <th>Type</th>
                    <th>Category</th>
                    <th>Date Added</th>
                    <th style="text-align: right;">Actions</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($gallery as $item): ?>
                    <tr>
                        <td>
                            <div style="display: flex; align-items: center; gap: 15px;">
                                <?php if ($item['type'] == 'image'): ?>
                                    <img src="<?= $item['file_path'] ?>" alt="" style="width: 40px; height: 40px; border-radius: 6px; object-fit: cover;">
                                <?php else: ?>
                                    <div style="width: 40px; height: 40px; border-radius: 6px; background: #333; display: flex; align-items: center; justify-content: center; color: #ff0000;">
                                        <i class="bi bi-play-circle-fill"></i>
                                    </div>
                                <?php endif; ?>
                                <span style="font-weight: 600;"><?= $item['title'] ?></span>
                            </div>
                        </td>
                        <td>
                            <span class="status-badge" style="background: <?= $item['type'] == 'image' ? 'rgba(0, 123, 255, 0.1)' : 'rgba(220, 53, 69, 0.1)' ?>; color: <?= $item['type'] == 'image' ? '#007bff' : '#dc3545' ?>;">
                                <?= ucfirst($item['type']) ?>
                            </span>
                        </td>
                        <td><?= $item['category'] ?? 'Uncategorized' ?></td>
                        <td style="color: var(--text-muted); font-size: 0.9rem;"><?= date('M d, Y', strtotime($item['created_at'])) ?></td>
                        <td style="text-align: right;">
                            <div style="display: flex; gap: 8px; justify-content: flex-end;">
                                <a href="<?= base_url('admin/gallery_delete/' . $item['id']) ?>" class="btn-action delete" title="Delete" onclick="return confirm('Are you sure?')"><i class="bi bi-trash-fill"></i></a>
                            </div>
                        </td>
                    </tr>
                <?php endforeach; ?>
                <?php if (empty($gallery)): ?>
                    <tr>
                        <td colspan="5" style="text-align: center; padding: 40px; color: var(--text-muted);">No media items found in the gallery.</td>
                    </tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>

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