<?php
require_once __DIR__ . '/includes/db.php';
require_once __DIR__ . '/includes/functions.php';

header('Content-Type: application/xml');

echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';

// Base URL
$baseUrl = 'http://localhost/fantastic_holidays';

// Static pages
$staticPages = [
    '' => 'daily',
    'packages.php' => 'daily',
    'hotels.php' => 'weekly',
    'activities.php' => 'weekly',
    'about.php' => 'monthly',
    'contact.php' => 'monthly',
    'b2b.php' => 'monthly',
    'enquiry.php' => 'weekly'
];

foreach ($staticPages as $page => $priority) {
    $url = $baseUrl . '/' . $page;
    echo "<url>";
    echo "<loc>{$url}</loc>";
    echo "<changefreq>{$priority}</changefreq>";
    echo "<priority>0.8</priority>";
    echo "</url>";
}

// Package pages
$packages = fetchAll("SELECT slug, updated_at FROM packages WHERE status = 'active'");
foreach ($packages as $package) {
    $url = $baseUrl . '/package-details.php?slug=' . $package['slug'];
    $lastmod = date('Y-m-d', strtotime($package['updated_at']));
    echo "<url>";
    echo "<loc>{$url}</loc>";
    echo "<lastmod>{$lastmod}</lastmod>";
    echo "<changefreq>weekly</changefreq>";
    echo "<priority>0.9</priority>";
    echo "</url>";
}

// Destination pages
$destinations = fetchAll("SELECT slug FROM destinations WHERE status = 'active'");
foreach ($destinations as $dest) {
    echo "<url>";
    echo "<loc>{$baseUrl}/packages.php?destination={$dest['slug']}</loc>";
    echo "<changefreq>weekly</changefreq>";
    echo "<priority>0.7</priority>";
    echo "</url>";
}

echo '</urlset>';
?>
