<?php
$pageTitle = 'Destinations';
require_once 'includes/header.php';

$db = getDBConnection();
$stmt = $db->query("SELECT p.*, (SELECT COUNT(*) FROM packages pk WHERE pk.place_id = p.id AND pk.status = 'active') as package_count FROM places p WHERE p.status = 'active' ORDER BY p.is_featured DESC, p.name ASC");
$places = $stmt->fetchAll();
?>

<div style="margin-top:75px;background:linear-gradient(135deg,var(--secondary),var(--secondary-dark));padding:60px 0;text-align:center;">
    <div class="container">
        <h1 style="color:#fff;font-size:2.5rem;margin-bottom:10px;">Explore Destinations</h1>
        <p style="color:rgba(255,255,255,0.8);font-size:1.1rem;">Discover breathtaking places across India</p>
    </div>
</div>

<section style="padding:60px 0;">
    <div class="container">
        <div class="places-grid">
            <?php foreach ($places as $place): ?>
                <a href="<?= BASE_URL ?>place.php?slug=<?= $place['slug'] ?>" class="place-card">
                    <img src="<?= getImageUrl($place['image'], 'places') ?>" alt="<?= sanitize($place['name']) ?>" loading="lazy">
                    <div class="place-overlay">
                        <div class="place-name"><?= sanitize($place['name']) ?></div>
                        <div class="place-packages"><?= $place['package_count'] ?> Tour Packages</div>
                    </div>
                    <?php if ($place['is_featured']): ?>
                        <span class="place-badge"><i class="fas fa-star"></i> Featured</span>
                    <?php endif; ?>
                </a>
            <?php endforeach; ?>
        </div>
    </div>
</section>

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