<?php
header('Content-Type: application/xml; charset=utf-8');
echo '<?xml version="1.0" encoding="UTF-8"?>';
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
        xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
    
    <!-- Home Page -->
    <url>
        <loc>https://btcnator.com/</loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq>daily</changefreq>
        <priority>1.0</priority>
    </url>

    <!-- Scripts Pages -->
    <?php
    require_once 'config.php';
    $scripts_result = $conn->query("SELECT slug, updated_at, title FROM scripts WHERE status='active' ORDER BY created_at DESC");
    while($script = $scripts_result->fetch_assoc()):
    ?>
    <url>
        <loc>https://btcnator.com/script/<?php echo htmlspecialchars($script['slug']); ?></loc>
        <lastmod><?php echo date('Y-m-d', strtotime($script['updated_at'])); ?></lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.9</priority>
    </url>
    <?php endwhile; ?>

    <!-- Category Pages -->
    <?php
    $categories_result = $conn->query("SELECT slug, name FROM categories WHERE status='active' ORDER BY name ASC");
    while($category = $categories_result->fetch_assoc()):
    ?>
    <url>
        <loc>https://btcnator.com/category/<?php echo htmlspecialchars($category['slug']); ?></loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.7</priority>
    </url>
    <?php endwhile; ?>

    <!-- Static Pages -->
    <url>
        <loc>https://btcnator.com/about</loc>
        <changefreq>monthly</changefreq>
        <priority>0.5</priority>
    </url>
    <url>
        <loc>https://btcnator.com/contact</loc>
        <changefreq>monthly</changefreq>
        <priority>0.5</priority>
    </url>
    <url>
        <loc>https://btcnator.com/privacy</loc>
        <changefreq>yearly</changefreq>
        <priority>0.3</priority>
    </url>

</urlset>