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

requireAdminLogin();

// Slider'ları listele
$stmt = $pdo->query("
    SELECT * FROM sliders
    ORDER BY sort_order ASC, created_at DESC
");
$sliders = $stmt->fetchAll();

$page_title = 'Slider Yönetimi';
include '../includes/header.php';
?>

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

<div class="card">
    <div class="card-body">
        <?php if (empty($sliders)): ?>
            <p class="text-muted text-center py-5">Henüz slider eklenmemiş.</p>
        <?php else: ?>
            <div class="table-responsive">
                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>Resim</th>
                            <th>Başlık</th>
                            <th>Link</th>
                            <th>Sıra</th>
                            <th>Durum</th>
                            <th>İşlemler</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($sliders as $slider): ?>
                            <tr>
                                <td><?= $slider['id'] ?></td>
                                <td>
                                    <img src="<?= e(getImageUrl($slider['image'])) ?>" alt="" style="width: 100px; height: 60px; object-fit: cover;">
                                </td>
                                <td><?= e($slider['title']) ?></td>
                                <td>
                                    <?php if ($slider['link']): ?>
                                        <a href="<?= e($slider['link']) ?>" target="_blank"><?= excerpt($slider['link'], 30) ?></a>
                                    <?php else: ?>
                                        <span class="text-muted">-</span>
                                    <?php endif; ?>
                                </td>
                                <td><?= $slider['sort_order'] ?></td>
                                <td>
                                    <span class="badge bg-<?= $slider['status'] === 'active' ? 'success' : 'secondary' ?>">
                                        <?= $slider['status'] === 'active' ? 'Aktif' : 'Pasif' ?>
                                    </span>
                                </td>
                                <td>
                                    <a href="edit.php?id=<?= $slider['id'] ?>" class="btn btn-sm btn-warning">
                                        <i class="fas fa-edit"></i>
                                    </a>
                                    <a href="delete.php?id=<?= $slider['id'] ?>" class="btn btn-sm btn-danger btn-delete" onclick="return confirm('Bu slider\'ı 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'; ?>




