<?php
require_once '../../config/config.php';
require_once '../../includes/auth.php';

requireAdminLogin();

// Sayfaları listele
$stmt = $pdo->query("
    SELECT * FROM pages
    ORDER BY created_at DESC
");
$pages = $stmt->fetchAll();

$page_title = 'Sayfalar';
include '../includes/header.php';
?>

<div class="d-flex justify-content-between align-items-center mb-4">
    <h1 class="h3">Sayfalar</h1>
    <a href="create.php" class="btn btn-primary">
        <i class="fas fa-plus me-2"></i>Yeni Sayfa Ekle
    </a>
</div>

<div class="card">
    <div class="card-body">
        <?php if (empty($pages)): ?>
            <p class="text-muted text-center py-5">Henüz sayfa eklenmemiş.</p>
        <?php else: ?>
            <div class="table-responsive">
                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>Başlık</th>
                            <th>Slug</th>
                            <th>Durum</th>
                            <th>Oluşturulma</th>
                            <th>Güncellenme</th>
                            <th>İşlemler</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($pages as $page): ?>
                            <tr>
                                <td><?= $page['id'] ?></td>
                                <td><?= e($page['title']) ?></td>
                                <td><code><?= e($page['slug']) ?></code></td>
                                <td>
                                    <span class="badge bg-<?= $page['status'] === 'published' ? 'success' : 'secondary' ?>">
                                        <?= $page['status'] === 'published' ? 'Yayında' : 'Taslak' ?>
                                    </span>
                                </td>
                                <td><?= formatDate($page['created_at'], 'd.m.Y H:i') ?></td>
                                <td><?= formatDate($page['updated_at'], 'd.m.Y H:i') ?></td>
                                <td>
                                    <a href="edit.php?id=<?= $page['id'] ?>" class="btn btn-sm btn-warning">
                                        <i class="fas fa-edit"></i>
                                    </a>
                                    <a href="delete.php?id=<?= $page['id'] ?>" class="btn btn-sm btn-danger btn-delete" onclick="return confirm('Bu sayfayı silmek istediğinize emin misiniz?')">
                                        <i class="fas fa-trash"></i>
                                    </a>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        <?php endif; ?>
    </div>
</div>

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


