<?php
declare(strict_types=1);
require_once __DIR__ . '/includes/functions.php';
$menu = loadJson('menu');
$enabledUrls = [];
foreach ($menu['mainMenu'] ?? [] as $item) {
    if ($item['enabled'] ?? true) {
        $enabledUrls[] = $item['url'];
    }
}

$pages = [
    'index.php' => ['loc' => 'https://akautokorjaamo.fi/', 'changefreq' => 'weekly', 'priority' => '1.0'],
    'services.php' => ['loc' => 'https://akautokorjaamo.fi/services.php', 'changefreq' => 'monthly', 'priority' => '0.8'],
    'about.php' => ['loc' => 'https://akautokorjaamo.fi/about.php', 'changefreq' => 'monthly', 'priority' => '0.7'],
    'contact.php' => ['loc' => 'https://akautokorjaamo.fi/contact.php', 'changefreq' => 'monthly', 'priority' => '0.8'],
];

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"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
        http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<?php foreach ($pages as $file => $data): ?>
<?php if (in_array($file, $enabledUrls)): ?>
    <url>
        <loc><?= htmlspecialchars($data['loc'], ENT_XML1, 'UTF-8') ?></loc>
        <lastmod><?= date('Y-m-d') ?></lastmod>
        <changefreq><?= $data['changefreq'] ?></changefreq>
        <priority><?= $data['priority'] ?></priority>
    </url>
<?php endif; ?>
<?php endforeach; ?>
</urlset>
