<?php
// This file is included by the AdminController, which will handle the layout
// No need to set $pageTitle here as it's already set in the controller
?>

<div class="admin-card">
    <div class="flex justify-between items-center mb-6">
        <h2 class="text-xl font-semibold">Pages</h2>
        <a href="/admin/pages/add" class="btn-primary">
            <i class="fas fa-plus mr-2"></i>Add New Page
        </a>
    </div>
    
    <?php if (empty($pages)): ?>
    <div class="bg-dark p-6 rounded-lg text-center">
        <i class="fas fa-file-alt text-4xl text-gray-500 mb-4"></i>
        <h3 class="text-lg font-medium mb-2">No Pages Yet</h3>
        <p class="text-gray-400 mb-4">Start creating pages for your website.</p>
        <a href="/admin/pages/add" class="btn-primary">
            <i class="fas fa-plus mr-2"></i>Create Your First Page
        </a>
    </div>
    <?php else: ?>
    <div class="overflow-x-auto">
        <table class="w-full">
            <thead>
                <tr>
                    <th class="text-left py-3 px-4 border-b border-gray-800">Title</th>
                    <th class="text-left py-3 px-4 border-b border-gray-800">Created</th>
                    <th class="text-right py-3 px-4 border-b border-gray-800">Actions</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($pages as $page): ?>
                <tr class="hover:bg-dark">
                    <td class="py-3 px-4 border-b border-gray-800">
                        <div class="flex items-center">
                            <?php if (!empty($page['featured_image'])): ?>
                            <div class="w-12 h-12 mr-3 rounded overflow-hidden flex-shrink-0">
                                <img src="<?= htmlspecialchars($page['featured_image']) ?>" alt="<?= htmlspecialchars($page['title']) ?>" class="w-full h-full object-cover">
                            </div>
                            <?php endif; ?>
                            <div>
                                <div class="font-medium"><?= htmlspecialchars($page['title']) ?></div>
                                <div class="text-sm text-gray-400">
                                    <a href="/page/<?= htmlspecialchars($page['slug']) ?>" target="_blank" class="hover:text-primary">
                                        <i class="fas fa-external-link-alt mr-1"></i>View
                                    </a>
                                </div>
                            </div>
                        </div>
                    </td>
                    <td class="py-3 px-4 border-b border-gray-800 text-gray-400">
                        <?= date('M j, Y', strtotime($page['created_at'])) ?>
                    </td>
                    <td class="py-3 px-4 border-b border-gray-800 text-right">
                        <div class="flex justify-end space-x-2">
                            <a href="/admin/pages/edit?id=<?= $page['id'] ?>" class="btn-icon" title="Edit">
                                <i class="fas fa-edit"></i>
                            </a>
                            <form method="POST" action="/admin/pages/delete" class="inline" onsubmit="return confirm('Are you sure you want to delete this page?');">
                                <input type="hidden" name="id" value="<?= $page['id'] ?>">
                                <button type="submit" class="btn-icon text-red-500" title="Delete">
                                    <i class="fas fa-trash-alt"></i>
                                </button>
                            </form>
                        </div>
                    </td>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
    <?php endif; ?>
</div> 