<?php
/**
 * Auto-generated XML Sitemap
 * Includes all static pages, portfolio items, and location pages
 */

require_once __DIR__ . '/includes/config.php';
require_once __DIR__ . '/includes/functions.php';
require_once __DIR__ . '/includes/json-storage.php';

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

// Base URL
$base = rtrim(BASE_URL, '/');

// Collect all URLs
$urls = [];

// Static pages
$static_pages = [
    ['loc' => '/', 'priority' => '1.0', 'changefreq' => 'weekly'],
    ['loc' => '/video-production', 'priority' => '0.9', 'changefreq' => 'weekly'],
    ['loc' => '/web-design', 'priority' => '0.9', 'changefreq' => 'weekly'],
    ['loc' => '/web-development', 'priority' => '0.9', 'changefreq' => 'weekly'],
    ['loc' => '/seo-services', 'priority' => '0.9', 'changefreq' => 'weekly'],
    ['loc' => '/live-streaming', 'priority' => '0.9', 'changefreq' => 'weekly'],
    ['loc' => '/corporate-video', 'priority' => '0.9', 'changefreq' => 'weekly'],
    ['loc' => '/portfolio', 'priority' => '0.8', 'changefreq' => 'weekly'],
    ['loc' => '/locations', 'priority' => '0.8', 'changefreq' => 'weekly'],
    ['loc' => '/about', 'priority' => '0.7', 'changefreq' => 'monthly'],
    ['loc' => '/contact', 'priority' => '0.8', 'changefreq' => 'monthly'],
    ['loc' => '/privacy', 'priority' => '0.3', 'changefreq' => 'yearly'],
    ['loc' => '/terms', 'priority' => '0.3', 'changefreq' => 'yearly'],
    ['loc' => '/sitemap', 'priority' => '0.4', 'changefreq' => 'monthly'],
];

foreach ($static_pages as $page) {
    $urls[] = $page;
}

// Portfolio items
$portfolio = get_portfolio_items();
foreach ($portfolio as $item) {
    if (!empty($item['slug'])) {
        $urls[] = [
            'loc' => '/portfolio/' . $item['slug'],
            'priority' => '0.7',
            'changefreq' => 'monthly',
        ];
    }
}

// Location pages
$locations = get_locations();
foreach ($locations as $location) {
    if (!empty($location['slug'])) {
        $urls[] = [
            'loc' => '/locations/' . $location['slug'],
            'priority' => '0.8',
            'changefreq' => 'monthly',
        ];
    }
}

// Generate sitemap XML
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<?php foreach ($urls as $url): ?>
    <url>
        <loc><?php echo $base . $url['loc']; ?></loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq><?php echo $url['changefreq']; ?></changefreq>
        <priority><?php echo $url['priority']; ?></priority>
    </url>
<?php endforeach; ?>
</urlset>
