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

requireAdminLogin();

// Blog yazılarını listele
$stmt = $pdo->query("
    SELECT * FROM blog_posts
    ORDER BY created_at DESC
");
$posts = $stmt->fetchAll();

$page_title = 'Blog Yazıları';
include '../includes/header.php';
?>

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

<div class="card">
    <div class="card-body">
        <?php if (empty($posts)): ?>
            <p class="text-muted text-center py-5">Henüz blog yazısı 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>Görüntülenme</th>
                            <th>Durum</th>
                            <th>Oluşturulma</th>
                            <th>İşlemler</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($posts as $post): ?>
                            <tr>
                                <td><?= $post['id'] ?></td>
                                <td><?= e($post['title']) ?></td>
                                <td><code><?= e($post['slug']) ?></code></td>
                                <td><?= $post['views'] ?></td>
                                <td>
                                    <span class="badge bg-<?= $post['status'] === 'published' ? 'success' : 'secondary' ?>">
                                        <?= $post['status'] === 'published' ? 'Yayında' : 'Taslak' ?>
                                    </span>
                                </td>
                                <td><?= formatDate($post['created_at'], 'd.m.Y H:i') ?></td>
                                <td>
                                    <a href="edit.php?id=<?= $post['id'] ?>" class="btn btn-sm btn-warning">
                                        <i class="fas fa-edit"></i>
                                    </a>
                                    <a href="delete.php?id=<?= $post['id'] ?>" class="btn btn-sm btn-danger btn-delete" onclick="return confirm('Bu yazıyı 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'; ?>





