<?php
header("Content-Type: application/xml; charset=utf-8");

$baseUrl = "https://www.fankado.com";

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

// 1. Core Static Pages
$staticPages = [
    ['loc' => '/', 'changefreq' => 'daily', 'priority' => '1.0'],
    ['loc' => '/carddrops.php', 'changefreq' => 'hourly', 'priority' => '0.9'],
    ['loc' => '/cards.php', 'changefreq' => 'hourly', 'priority' => '0.9'],
    ['loc' => '/milestones.php', 'changefreq' => 'weekly', 'priority' => '0.8'],
    ['loc' => '/about.php', 'changefreq' => 'monthly', 'priority' => '0.5']
];

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

// 2. Dynamic Database Queries (Using your existing DB connection)
try {
    // Assuming you have a global $pdo or DB connection available:
    // global $pdo; 

    // --- Fetch Public Drops ---
    // Replace 'drops', 'slug_column', and 'updated_at' with your actual table/column names
    /*
    $stmt = $pdo->query("SELECT slug, updated_at FROM drops WHERE status != 'draft'");
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
        echo '<url>';
        echo '<loc>' . $baseUrl . '/d/' . htmlspecialchars($row['slug'], ENT_XML1, 'UTF-8') . '</loc>';
        if (!empty($row['updated_at'])) {
            echo '<lastmod>' . date('Y-m-d', strtotime($row['updated_at'])) . '</lastmod>';
        }
        echo '<changefreq>weekly</changefreq>';
        echo '<priority>0.8</priority>';
        echo '</url>';
    }
    */

    // --- Fetch Public Cards ---
    // Replace 'cards', 'slug_column', and 'updated_at' with your actual table/column names
    /*
    $stmtCards = $pdo->query("SELECT slug, updated_at FROM cards");
    while ($row = $stmtCards->fetch(PDO::FETCH_ASSOC)) {
        echo '<url>';
        echo '<loc>' . $baseUrl . '/card/' . htmlspecialchars($row['slug'], ENT_XML1, 'UTF-8') . '</loc>';
        if (!empty($row['updated_at'])) {
            echo '<lastmod>' . date('Y-m-d', strtotime($row['updated_at'])) . '</lastmod>';
        }
        echo '<changefreq>monthly</changefreq>';
        echo '<priority>0.7</priority>';
        echo '</url>';
    }
    */

} catch (Exception $e) {
    // Fail silently or log error so the XML structure doesn't break entirely if DB drops
}

echo '</urlset>';
?>