<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    <url>
        <loc><?= SITE_URL ?></loc>
        <lastmod><?= date('Y-m-d') ?></lastmod>
        <changefreq>daily</changefreq>
        <priority>1.0</priority>
    </url>
    <url>
        <loc><?= SITE_URL ?>/about.php</loc>
        <lastmod><?= date('Y-m-d') ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.8</priority>
    </url>
    <url>
        <loc><?= SITE_URL ?>/contact.php</loc>
        <lastmod><?= date('Y-m-d') ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.8</priority>
    </url>
    <?php
    // اضافه کردن URL محصولات
    $db = new Database();
    $products = $db->query("SELECT id, updated_at FROM products WHERE status = 1");
    foreach ($products as $product) {
        $url = SITE_URL . '/product-detail.php?id=' . $product['id'];
        $lastmod = date('Y-m-d', strtotime($product['updated_at']));
        echo "<url>
                <loc>{$url}</loc>
                <lastmod>{$lastmod}</lastmod>
                <changefreq>weekly</changefreq>
                <priority>0.6</priority>
              </url>";
    }
    
    // اضافه کردن URL دسته‌بندی‌ها
    $categories = $db->query("SELECT id FROM categories WHERE status = 1");
    foreach ($categories as $category) {
        $url = SITE_URL . '/category.php?id=' . $category['id'];
        echo "<url>
                <loc>{$url}</loc>
                <lastmod>" . date('Y-m-d') . "</lastmod>
                <changefreq>weekly</changefreq>
                <priority>0.7</priority>
              </url>";
    }
    ?>
</urlset>