<?php
/**
 * sitemap.php — served at /sitemap.xml by a rewrite in .htaccess.
 *
 * GENERATED, not static, for one reason: the site lists a different set of URLs
 * before and after LAUNCH_LOCAL, and a static file would have to be edited on
 * the morning. It reads the same clock as partials/gate.php and the countdown
 * itself, so the three can never disagree about whether the site is live.
 *
 * BEFORE LAUNCH: one URL. Every other path 302s to the countdown, and listing a
 * URL that redirects is how you teach a crawler to distrust the file.
 *
 * AFTER LAUNCH: the nine indexable pages. /thank-you and the 404 stay out —
 * both carry noindex, and listing a page you have told Google not to index is a
 * contradiction it resolves by trusting this file less.
 *
 * <lastmod> is the launch date, not today's: a file where every date moves on
 * every deploy stops being a recrawl signal and becomes noise.
 */
declare(strict_types=1);

require_once __DIR__ . '/v3/config.php';

header('Content-Type: application/xml; charset=UTF-8');

$base = rtrim(APP_URL, '/');
$live = v3_is_live();
$mod  = v3_launch_at()->format('Y-m-d');

$urls = $live ? [
    ['/',         'weekly',  '1.0'],
    ['/features', 'monthly', '0.9'],
    ['/about',    'monthly', '0.8'],
    ['/security', 'monthly', '0.8'],
    ['/contact',  'monthly', '0.8'],
    ['/privacy',  'yearly',  '0.3'],
    ['/terms',    'yearly',  '0.3'],
    ['/paia',     'yearly',  '0.3'],
    ['/dpa',      'yearly',  '0.3'],
] : [
    ['/',         'daily',   '1.0'],
];

echo '<?xml version="1.0" encoding="UTF-8"?>', "\n";
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">', "\n";
foreach ($urls as [$path, $freq, $priority]) {
    echo "  <url>\n";
    echo '    <loc>', htmlspecialchars($base . $path, ENT_QUOTES, 'UTF-8'), "</loc>\n";
    echo '    <lastmod>', $mod, "</lastmod>\n";
    echo '    <changefreq>', $freq, "</changefreq>\n";
    echo '    <priority>', $priority, "</priority>\n";
    echo "  </url>\n";
}
echo '</urlset>', "\n";
