<?php
header('Content-Type: application/xml; charset=utf-8');
require_once 'inc/config.php';

$urls = [];

// Ana sayfa
$urls[] = ['loc' => 'https://cocbuild.com/', 'priority' => '1.0'];

// Town Hall sayfaları (TH4 - TH18)
for ($th = 4; $th <= 18; $th++) {
    $urls[] = ['loc' => "https://cocbuild.com/th.php?th=$th", 'priority' => '0.8'];
}

// Builder Hall sayfaları (BH3 - BH10)
for ($bh = 3; $bh <= 10; $bh++) {
    $urls[] = ['loc' => "https://cocbuild.com/bh.php?bh=$bh", 'priority' => '0.8'];
}

// Capital Hall district'ler
$districts = ['capital-peak', 'barbarian-camp', 'wizard-valley', 'balloon-lagoon', 'builders-workshop', 'dragon-cliff', 'golem-quarry', 'skeleton-park', 'goblin-mines'];
foreach ($districts as $district) {
    $urls[] = ['loc' => "https://cocbuild.com/ch.php?district=$district", 'priority' => '0.7'];
}

// Base detay sayfaları (sadece onaylanmış)
$stmt = $pdo->query("SELECT id, date_added FROM bases WHERE status = 'approved' ORDER BY id DESC");
$bases = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($bases as $base) {
    $urls[] = ['loc' => "https://cocbuild.com/base.php?id={$base['id']}", 'priority' => '0.6'];
}

// Statik sayfalar
$static_pages = ['contact', 'privacy', 'cookie', 'terms', 'faq', 'blog'];
foreach ($static_pages as $page) {
    $urls[] = ['loc' => "https://cocbuild.com/$page.php", 'priority' => '0.5'];
}

// XML çıktısı
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
foreach ($urls as $url) {
    echo '<url>';
    echo '<loc>' . htmlspecialchars($url['loc']) . '</loc>';
    echo '<priority>' . $url['priority'] . '</priority>';
    echo '</url>';
}
echo '</urlset>';
?>