<?php
/**
 * sitemap.xml — Dynamic XML Sitemap Generator
 * Outputs a valid XML sitemap for all public pages
 * Access: https://yourdomain.com/sitemap.xml
 *
 * @package SheetMetalPro
 */

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

header('Content-Type: application/xml; charset=UTF-8');
header('X-Robots-Tag: noindex');

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
/**
 * Define all public pages with their SEO priority and change frequency.
 * Format: [relative_url, priority, changefreq]
 */
$pages = [
    // Homepage — highest priority
    ['/',                            '1.0', 'weekly'],

    // Core pages
    ['/pages/about.php',             '0.9', 'monthly'],
    ['/pages/infrastructure.php',    '0.9', 'monthly'],
    ['/pages/services.php',          '0.9', 'monthly'],
    ['/pages/industries.php',        '0.8', 'monthly'],
    ['/pages/gallery.php',           '0.7', 'weekly'],
    ['/pages/certifications.php',    '0.7', 'monthly'],
    ['/pages/contact.php',           '0.9', 'monthly'],

    // Anchored deep-links for services (optional — helps indexing)
    ['/pages/services.php#laser-cutting',  '0.7', 'monthly'],
    ['/pages/services.php#cnc-punching',   '0.7', 'monthly'],
    ['/pages/services.php#cnc-bending',    '0.7', 'monthly'],
    ['/pages/services.php#prototyping',    '0.6', 'monthly'],
    ['/pages/services.php#batch',          '0.6', 'monthly'],

    // Infrastructure anchors
    ['/pages/infrastructure.php#laser',    '0.7', 'monthly'],
    ['/pages/infrastructure.php#punching', '0.7', 'monthly'],
    ['/pages/infrastructure.php#bending',  '0.7', 'monthly'],

    // Industries
    ['/pages/industries.php#electrical',   '0.6', 'monthly'],
    ['/pages/industries.php#telecom',      '0.6', 'monthly'],
    ['/pages/industries.php#hvac',         '0.6', 'monthly'],
    ['/pages/industries.php#automotive',   '0.6', 'monthly'],
    ['/pages/industries.php#automation',   '0.6', 'monthly'],
    ['/pages/industries.php#oem',          '0.6', 'monthly'],

    // Legal
    ['/pages/privacy-policy.php',   '0.3', 'yearly'],
    ['/pages/terms.php',            '0.3', 'yearly'],
];

$today = date('Y-m-d');
foreach ($pages as [$url, $priority, $changefreq]):
    $fullUrl = rtrim(SITE_URL, '/') . $url;
?>
    <url>
        <loc><?= htmlspecialchars($fullUrl, ENT_XML1) ?></loc>
        <lastmod><?= $today ?></lastmod>
        <changefreq><?= $changefreq ?></changefreq>
        <priority><?= $priority ?></priority>
    </url>
<?php endforeach; ?>

</urlset>
