<?php
header("Content-Type: application/xml; charset=utf-8");

$languages = ['fr', 'nl'];
$cities = json_decode(file_get_contents('data/cities.json'), true);
$regions = json_decode(file_get_contents('data/regions.json'), true);

$base_url = "https://devischassisfenetres.be";

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

foreach ($languages as $l) {
    // Home
    echo '<url>';
    echo '<loc>' . $base_url . '/' . $l . '/</loc>';
    echo '<changefreq>weekly</changefreq>';
    echo '<priority>1.0</priority>';
    echo '</url>';

    // Regions
    foreach ($regions as $r) {
        $prefix = ($l === 'fr' ? 'region/' : 'regio/');
        echo '<url>';
        echo '<loc>' . $base_url . '/' . $l . '/' . $prefix . $r['slug'] . '</loc>';
        echo '<changefreq>monthly</changefreq>';
        echo '<priority>0.8</priority>';
        echo '</url>';
    }

    // Cities
    $city_prefix = ($l === 'fr' ? 'devis-chassis-' : 'offerte-ramen-');
    foreach (array_slice($cities, 0, 300) as $c) {
        echo '<url>';
        echo '<loc>' . $base_url . '/' . $l . '/' . $city_prefix . $c['slug'] . '</loc>';
        echo '<changefreq>monthly</changefreq>';
        echo '<priority>0.6</priority>';
        echo '</url>';
    }
}

echo '</urlset>';
?>