<?php
/** Sitemap XML dinamica. */
declare(strict_types=1);

require_once __DIR__ . '/includes/config.php';
require_once __DIR__ . '/includes/db.php';

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

$base = rtrim(SITE_URL, '/');
$today = date('Y-m-d');

$pages = [
    ['/', '1.0', 'daily'],
    ['/menu', '0.9', 'weekly'],
    ['/dove-siamo', '0.9', 'daily'],
    ['/catering-eventi', '0.8', 'weekly'],
    ['/galleria', '0.7', 'weekly'],
    ['/contatti', '0.6', 'monthly'],
    ['/privacy', '0.3', 'yearly'],
    ['/cookie', '0.3', 'yearly'],
];

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