<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    
    <!-- صفحه اصلی -->
    <url>
        <loc>https://YOUR_DOMAIN.com/</loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq>daily</changefreq>
        <priority>1.0</priority>
    </url>
    
    <!-- صفحات اصلی -->
    <url>
        <loc>https://YOUR_DOMAIN.com/chats</loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.8</priority>
    </url>
    <url>
        <loc>https://YOUR_DOMAIN.com/news</loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.8</priority>
    </url>
    <url>
        <loc>https://YOUR_DOMAIN.com/assistant</loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.7</priority>
    </url>
    <url>
        <loc>https://YOUR_DOMAIN.com/profile</loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.7</priority>
    </url>

    <?php
    // اتصال به دیتابیس
    require_once 'config.php';
    
    // دریافت همه دسته‌بندی‌ها
    $stmt = $pdo->query("SELECT DISTINCT category FROM apps WHERE is_active = 1");
    $categories = $stmt->fetchAll(PDO::FETCH_COLUMN);
    
    foreach ($categories as $category): 
    ?>
    <url>
        <loc>https://YOUR_DOMAIN.com/category/<?= urlencode($category) ?></loc>
        <lastmod><?= date('Y-m-d') ?></lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.7</priority>
    </url>
    <?php endforeach; ?>
    
    <!-- اپلیکیشن‌ها -->
    <?php
    $stmt = $pdo->query("SELECT name, code, updated_at, created_at FROM apps WHERE is_active = 1 ORDER BY created_at DESC");
    $apps = $stmt->fetchAll();
    foreach ($apps as $app): 
    ?>
    <url>
        <loc>https://YOUR_DOMAIN.com/<?= $app['code'] ?>/<?= urlencode($app['name']) ?></loc>
        <lastmod><?= date('Y-m-d', strtotime($app['updated_at'] ?? $app['created_at'])) ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.9</priority>
    </url>
    <?php endforeach; ?>
    
    <!-- اخبار -->
    <?php
    $stmt = $pdo->query("SELECT title, updated_at, created_at FROM news WHERE is_active = 1 ORDER BY created_at DESC");
    $news = $stmt->fetchAll();
    foreach ($news as $item): 
    ?>
    <url>
        <loc>https://YOUR_DOMAIN.com/news/<?= urlencode($item['title']) ?></loc>
        <lastmod><?= date('Y-m-d', strtotime($item['updated_at'] ?? $item['created_at'])) ?></lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.8</priority>
    </url>
    <?php endforeach; ?>
    
</urlset>