<?php
header('Content-Type: application/xml; charset=utf-8');
echo '<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';

$base_url = 'https://hookedonchains.in';
$pages = [
    ['url' => '/', 'priority' => '1.0', 'changefreq' => 'daily'],
    ['url' => '/shop.php', 'priority' => '0.9', 'changefreq' => 'daily'],
    ['url' => '/reviews.php', 'priority' => '0.8', 'changefreq' => 'weekly'],
    ['url' => '/about.php', 'priority' => '0.7', 'changefreq' => 'monthly'],
    ['url' => '/custom-order.php', 'priority' => '0.8', 'changefreq' => 'weekly'],
    ['url' => '/contact.php', 'priority' => '0.7', 'changefreq' => 'monthly'],
    ['url' => '/cart.php', 'priority' => '0.6', 'changefreq' => 'daily'],
    ['url' => '/login.php', 'priority' => '0.5', 'changefreq' => 'yearly'],
    ['url' => '/register.php', 'priority' => '0.5', 'changefreq' => 'yearly'],
    ['url' => '/wishlist.php', 'priority' => '0.6', 'changefreq' => 'weekly'],
];

// Get all products from data.php
require_once 'includes/data.php';
foreach ($all_products as $product) {
    $pages[] = [
        'url' => '/product.php?id=' . $product['id'],
        'priority' => '0.8',
        'changefreq' => 'weekly'
    ];
}

// Get all categories
$categories = array_unique(array_column($all_products, 'category'));
foreach ($categories as $cat) {
    $pages[] = [
        'url' => '/shop.php?cat=' . urlencode($cat),
        'priority' => '0.7',
        'changefreq' => 'weekly'
    ];
}

foreach ($pages as $page) {
    echo "
  <url>
    <loc>" . htmlspecialchars($base_url . $page['url']) . "</loc>
    <lastmod>" . date('Y-m-d') . "</lastmod>
    <changefreq>" . htmlspecialchars($page['changefreq']) . "</changefreq>
    <priority>" . htmlspecialchars($page['priority']) . "</priority>
  </url>";
}

echo '
</urlset>';
?>