<?php
/**
 * Dynamic Sitemap Generator
 */
header('Content-Type: application/xml; charset=utf-8');

$base_url = 'https://bmig.pl';
$languages = ['pl', 'en', 'de'];
$pages = [
    '' => ['priority' => '1.0', 'changefreq' => 'daily'],
    'about.php' => ['priority' => '0.8', 'changefreq' => 'monthly'],
    'activities.php' => ['priority' => '0.8', 'changefreq' => 'monthly'],
    'products.php' => ['priority' => '0.9', 'changefreq' => 'weekly'],
    'contact.php' => ['priority' => '0.7', 'changefreq' => 'monthly'],
    'regulamin.php' => ['priority' => '0.3', 'changefreq' => 'yearly'],
    'polityka-prywatnosci.php' => ['priority' => '0.3', 'changefreq' => 'yearly'],
    'polityka-cookies.php' => ['priority' => '0.3', 'changefreq' => 'yearly'],
];

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

foreach ($pages as $page => $settings) {
    foreach ($languages as $lang) {
        $url = $base_url . ($page ? '/' . $page : '');
        if ($lang != 'pl') {
            $url .= (strpos($url, '?') !== false ? '&' : '?') . 'lang=' . $lang;
        }
        
        echo '  <url>' . "\n";
        echo '    <loc>' . htmlspecialchars($url) . '</loc>' . "\n";
        echo '    <lastmod>' . date('Y-m-d') . '</lastmod>' . "\n";
        echo '    <changefreq>' . $settings['changefreq'] . '</changefreq>' . "\n";
        echo '    <priority>' . $settings['priority'] . '</priority>' . "\n";
        
        // Alternate language versions
        foreach ($languages as $alt_lang) {
            $alt_url = $base_url . ($page ? '/' . $page : '');
            if ($alt_lang != 'pl') {
                $alt_url .= (strpos($alt_url, '?') !== false ? '&' : '?') . 'lang=' . $alt_lang;
            }
            echo '    <xhtml:link rel="alternate" hreflang="' . $alt_lang . '" href="' . htmlspecialchars($alt_url) . '" />' . "\n";
        }
        
        echo '  </url>' . "\n";
    }
}

echo '</urlset>';


