<?php
/**
 * sitemap.xml
 * Dynamic sitemap covering only the publicly accessible pages.
 * Authenticated routes are excluded — they are noindex anyway.
 *
 * Access: http://localhost:8000/sms_mobilo/sitemap.xml
 */

require_once __DIR__ . '/assets/init.php';

$baseUrl  = rtrim(cfg('platform_url', ''), '/') . APP_BASE;
$now      = date('Y-m-d');
$regOpen  = cfg('registration_open', '1') === '1';

$urls = [
    ['loc' => $baseUrl . '/login',           'priority' => '1.0',  'freq' => 'monthly'],
    ['loc' => $baseUrl . '/forgot-password', 'priority' => '0.5',  'freq' => 'yearly'],
];

if ($regOpen) {
    $urls[] = ['loc' => $baseUrl . '/register', 'priority' => '0.9', 'freq' => 'monthly'];
}

header('Content-Type: application/xml; charset=utf-8');
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<?php foreach ($urls as $url): ?>
  <url>
    <loc><?= htmlspecialchars($url['loc']) ?></loc>
    <lastmod><?= $now ?></lastmod>
    <changefreq><?= $url['freq'] ?></changefreq>
    <priority><?= $url['priority'] ?></priority>
  </url>
<?php endforeach; ?>
</urlset>
