<?php
/**
 * CreativeAlt — Dynamic XML Sitemap
 * Automatically renders a clean, standards-compliant XML sitemap for search engines.
 */

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

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

$baseUrl = rtrim(APP_URL, '/');

$pages = [
    // Primary Pages
    ['loc' => '', 'priority' => '1.0', 'changefreq' => 'weekly'],
    ['loc' => 'about', 'priority' => '0.8', 'changefreq' => 'monthly'],
    ['loc' => 'services', 'priority' => '0.9', 'changefreq' => 'weekly'],
    ['loc' => 'team', 'priority' => '0.7', 'changefreq' => 'monthly'],
    ['loc' => 'careers', 'priority' => '0.8', 'changefreq' => 'weekly'],
    ['loc' => 'insights', 'priority' => '0.8', 'changefreq' => 'weekly'],
    ['loc' => 'contact', 'priority' => '0.9', 'changefreq' => 'monthly'],
    ['loc' => 'faq', 'priority' => '0.6', 'changefreq' => 'monthly'],
    ['loc' => 'testimonials', 'priority' => '0.7', 'changefreq' => 'monthly'],

    // Services: Website Design
    ['loc' => 'web-design-development', 'priority' => '0.85', 'changefreq' => 'monthly'],
    ['loc' => 'user-experience-design', 'priority' => '0.85', 'changefreq' => 'monthly'],
    ['loc' => 'user-interface-design', 'priority' => '0.85', 'changefreq' => 'monthly'],
    ['loc' => 'content-strategy', 'priority' => '0.85', 'changefreq' => 'monthly'],

    // Services: Brand Strategy
    ['loc' => 'packaging-design-services', 'priority' => '0.85', 'changefreq' => 'monthly'],
    ['loc' => 'corporate-identity', 'priority' => '0.85', 'changefreq' => 'monthly'],
    ['loc' => 'graphic-design', 'priority' => '0.85', 'changefreq' => 'monthly'],
    ['loc' => 'logo-design', 'priority' => '0.85', 'changefreq' => 'monthly'],

    // Services: Digital Marketing
    ['loc' => 'social-media-strategy', 'priority' => '0.85', 'changefreq' => 'monthly'],
    ['loc' => 'content-marketing', 'priority' => '0.85', 'changefreq' => 'monthly'],
    ['loc' => 'email-marketing', 'priority' => '0.85', 'changefreq' => 'monthly'],
    ['loc' => 'seo-strategy', 'priority' => '0.85', 'changefreq' => 'monthly'],

    // Our Launch
    ['loc' => 'hello-ai', 'priority' => '0.9', 'changefreq' => 'weekly'],
    ['loc' => 'analytics', 'priority' => '0.85', 'changefreq' => 'monthly'],
    ['loc' => 'seo', 'priority' => '0.85', 'changefreq' => 'monthly'],
    ['loc' => 'crm', 'priority' => '0.85', 'changefreq' => 'monthly'],

    // Our Products
    ['loc' => 'elementor-ai', 'priority' => '0.85', 'changefreq' => 'monthly'],
    ['loc' => 'wp-security', 'priority' => '0.85', 'changefreq' => 'monthly'],
    ['loc' => 'hosting', 'priority' => '0.85', 'changefreq' => 'monthly'],

    // Shop & Client Pages
    ['loc' => 'shop', 'priority' => '0.9', 'changefreq' => 'weekly'],
    ['loc' => 'changelog', 'priority' => '0.7', 'changefreq' => 'weekly'],

    // Legal & Policies
    ['loc' => 'privacy-policy', 'priority' => '0.5', 'changefreq' => 'yearly'],
    ['loc' => 'terms-of-service', 'priority' => '0.5', 'changefreq' => 'yearly'],
    ['loc' => 'security-standards', 'priority' => '0.5', 'changefreq' => 'yearly'],
];

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