<?php
require_once __DIR__ . '/config.php';
require_once __DIR__ . '/includes/header.php';

// Fetch ticket posts
try {
    $stmt = $pdo->prepare("
        SELECT id, title, slug, tagline, image_path 
        FROM posts 
        WHERE post_location = :loc 
        ORDER BY created_at DESC
    ");
    $stmt->execute(['loc' => 'tickets']);
    $tickets = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
    $tickets = [];
}

$extra_head = '<link rel="stylesheet" href="/styles/park.css">';
require_once __DIR__ . '/includes/header.php';
?>

<main class="news-page">
    <section class="hero-news">
        <div class="hero-text">
            <h1 class="title-alt">Tickets & Offers</h1>
        </div>
    </section>

    <section class="container py-5">
        <?php if (empty($tickets)): ?>
            <p>No ticket pages yet.</p>
        <?php else: ?>
            <div class="row g-4">
                <?php foreach ($tickets as $ticket): ?>
                    <div class="col-md-3 col-sm-6">
                        <a href="/tickets-offers/<?= urlencode($ticket['slug']) ?>" class="text-decoration-none text-dark">
                            <div class="card h-100 shadow-sm">
                                <img src="/<?= htmlspecialchars($ticket['image_path'] ?? 'assets/default.jpg') ?>"
                                     class="card-img-top park-img"
                                     alt="<?= htmlspecialchars($ticket['title']) ?>">
<div class="card-body text-center d-flex flex-column">
    <h5 class="card-title mb-1" style="color:#000 !important;">
        <?= htmlspecialchars($ticket['title']) ?>
    </h5>

    <?php if (!empty($ticket['tagline'])): ?>
        <p class="text-muted small mb-3">
            <?= htmlspecialchars($ticket['tagline']) ?>
        </p>
    <?php endif; ?>

    <!-- Push button to bottom -->
    <div class="mt-auto">
        <span class="btn btn-warning w-100 fw-semibold">
            View Deals
        </span>
    </div>
</div>
                            </div>
                        </a>
                    </div>
                <?php endforeach; ?>
            </div>
        <?php endif; ?>
    </section>
</main>

<?php require_once __DIR__ . '/includes/footer.php'; ?>