<?php
header('Content-Type: application/xml; charset=utf-8');
require_once 'config.php';

$base = SITE_URL;

// Static pages
$static_pages = [
    ['loc' => $base . '/', 'priority' => '1.0', 'changefreq' => 'weekly'],
    ['loc' => $base . '/index.php', 'priority' => '1.0', 'changefreq' => 'weekly'],
    ['loc' => $base . '/about-us.php', 'priority' => '0.8', 'changefreq' => 'monthly'],
];

// Fetch tour packages
$tours = [];
$result = $conn->query("SELECT id, title, date_range FROM tours ORDER BY id DESC");
if ($result) {
    $tours = $result->fetch_all(MYSQLI_ASSOC);
}

echo '<?xml version="1.0" encoding="UTF-8"?>';
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <?php foreach ($static_pages as $page): ?>
  <url>
    <loc><?php echo htmlspecialchars($page['loc']); ?></loc>
    <lastmod><?php echo date('Y-m-d'); ?></lastmod>
    <changefreq><?php echo $page['changefreq']; ?></changefreq>
    <priority><?php echo $page['priority']; ?></priority>
  </url>
  <?php endforeach; ?>
  <?php foreach ($tours as $tour): ?>
  <url>
    <loc><?php echo $base; ?>/package.php?id=<?php echo $tour['id']; ?></loc>
    <lastmod><?php echo date('Y-m-d'); ?></lastmod>
    <changefreq>weekly</changefreq>
    <priority>0.9</priority>
  </url>
  <?php endforeach; ?>
</urlset>
