<?php
require_once __DIR__ . '/includes/config.php';

header('Content-Type: application/xml; charset=UTF-8');
header('X-Robots-Tag: noindex'); // Sitemap itself should not be indexed as a page

$pages = [
    ['loc' => '/',         'priority' => '1.0', 'changefreq' => 'weekly',  'file' => 'index.php',    'image' => 'media/art-hero-1.jpg',        'caption' => 'Bal Madhuban — publish Hindi stories and kids books'],
    ['loc' => '/features', 'priority' => '0.9', 'changefreq' => 'monthly', 'file' => 'features.php', 'image' => 'media/art-features-hero.jpg', 'caption' => 'Publishing, analytics, and ad commission tools for kids story creators'],
    ['loc' => '/creators', 'priority' => '0.9', 'changefreq' => 'monthly', 'file' => 'creators.php', 'image' => 'media/art-creators-hero.jpg', 'caption' => 'Hindi storytellers and children book authors on Bal Madhuban'],
    ['loc' => '/pricing',  'priority' => '0.8', 'changefreq' => 'monthly', 'file' => 'pricing.php',  'image' => 'media/art-pricing-hero.jpg',  'caption' => 'Free forever and Creator Pro plans for Hindi story creators'],
    ['loc' => '/about',    'priority' => '0.8', 'changefreq' => 'monthly', 'file' => 'about.php',    'image' => 'media/art-about-hero.jpg',    'caption' => 'The story behind the @balmadhuban Hindi kids podcast'],
    ['loc' => '/contact',  'priority' => '0.7', 'changefreq' => 'monthly', 'file' => 'contact.php',  'image' => 'media/art-contact-hero.jpg',  'caption' => 'Contact the Bal Madhuban creator support team'],
    ['loc' => '/press',    'priority' => '0.6', 'changefreq' => 'yearly',  'file' => 'press.php',    'image' => 'media/logo.png',              'caption' => 'Bal Madhuban press kit and brand assets'],
    ['loc' => '/privacy',  'priority' => '0.4', 'changefreq' => 'yearly',  'file' => 'privacy.php',  'image' => 'media/art-og-default.jpg',    'caption' => 'Bal Madhuban privacy policy'],
];

echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
        xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
<?php foreach ($pages as $page):
    /* Use real file modification time instead of always today's date */
    $filepath = __DIR__ . '/' . $page['file'];
    $lastmod = is_file($filepath) ? date('Y-m-d', filemtime($filepath)) : date('Y-m-d');
    $loc = htmlspecialchars(rtrim(SITE_URL, '/') . $page['loc']);
?>
  <url>
    <loc><?= $loc ?></loc>
    <lastmod><?= $lastmod ?></lastmod>
    <changefreq><?= $page['changefreq'] ?></changefreq>
    <priority><?= $page['priority'] ?></priority>
    <image:image>
      <image:loc><?= htmlspecialchars(rtrim(SITE_URL, '/') . '/' . ltrim($page['image'], '/')) ?></image:loc>
      <image:caption><?= htmlspecialchars($page['caption']) ?></image:caption>
    </image:image>
  </url>
<?php endforeach; ?>
</urlset>
