<?php

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

$config = require __DIR__ . '/config.php';
$base = rtrim((string) ($config['site_url'] ?? ''), '/');

if ($base === '') {
    $https = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off';
    $host = $_SERVER['HTTP_HOST'] ?? 'localhost';
    $base = ($https ? 'https' : 'http') . '://' . $host;
}

$hoje = date('Y-m-d');
$urls = [
    ['path' => '/', 'priority' => '1.0', 'changefreq' => 'weekly'],
    ['path' => '/#servicos', 'priority' => '0.9', 'changefreq' => 'weekly'],
    ['path' => '/#empresas', 'priority' => '0.8', 'changefreq' => 'monthly'],
    ['path' => '/#como-funciona', 'priority' => '0.7', 'changefreq' => 'monthly'],
    ['path' => '/#cotacao', 'priority' => '0.9', 'changefreq' => 'monthly'],
    ['path' => '/#faq', 'priority' => '0.6', 'changefreq' => 'monthly'],
];

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

foreach ($urls as $url) {
    $loc = htmlspecialchars($base . $url['path'], ENT_XML1);
    echo "  <url>\n";
    echo "    <loc>{$loc}</loc>\n";
    echo "    <lastmod>{$hoje}</lastmod>\n";
    echo "    <changefreq>{$url['changefreq']}</changefreq>\n";
    echo "    <priority>{$url['priority']}</priority>\n";
    echo "  </url>\n";
}

echo '</urlset>';
