<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" 
        xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
    
    <!-- Главная страница -->
    <url>
        <loc>https://elektromir-rostov.ru/</loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq>weekly</changefreq>
        <priority>1.0</priority>
        <image:image>
            <image:loc>https://elektromir-rostov.ru/assets/img/common/logo.png</image:loc>
            <image:title>Электромир - электротехническое оборудование</image:title>
        </image:image>
    </url>
    
    <!-- Каталог -->
    <url>
        <loc>https://elektromir-rostov.ru/catalog</loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.9</priority>
    </url>
    
    <!-- Категории каталога -->
    <url>
        <loc>https://elektromir-rostov.ru/catalog-category</loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.8</priority>
    </url>
    
    <?php
    // Подключаемся к БД для получения категорий
    try {
        require_once __DIR__ . '/admin/db.php';
        $categories_result = $conn->query("SELECT * FROM catalog_categories WHERE is_active = 1 ORDER BY sort_order ASC, name ASC");
        if ($categories_result) {
            while ($category = $categories_result->fetch_assoc()) {
                echo "    <url>\n";
                echo "        <loc>https://elektromir-rostov.ru/catalog-category/" . urlencode($category['slug']) . "/</loc>\n";
                echo "        <lastmod>" . date('Y-m-d', strtotime($category['updated_at'] ?: $category['created_at'])) . "</lastmod>\n";
                echo "        <changefreq>monthly</changefreq>\n";
                echo "        <priority>0.8</priority>\n";
                echo "    </url>\n";
            }
        }
    } catch (Exception $e) {
        // Если БД недоступна, пропускаем динамические категории
    }
    ?>
    
    <!-- Услуги -->
    <url>
        <loc>https://elektromir-rostov.ru/services</loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.8</priority>
    </url>
    
    <!-- Детальные страницы услуг -->
    <url>
        <loc>https://elektromir-rostov.ru/service-detail</loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.7</priority>
    </url>
    
    <?php
    try {
        $services_result = $conn->query("SELECT * FROM services WHERE is_active = 1 ORDER BY sort_order ASC, title ASC");
        if ($services_result) {
            while ($service = $services_result->fetch_assoc()) {
                echo "    <url>\n";
                echo "        <loc>https://elektromir-rostov.ru/service-detail/" . urlencode($service['slug']) . "/</loc>\n";
                echo "        <lastmod>" . date('Y-m-d', strtotime($service['updated_at'] ?: $service['created_at'])) . "</lastmod>\n";
                echo "        <changefreq>monthly</changefreq>\n";
                echo "        <priority>0.7</priority>\n";
                echo "    </url>\n";
            }
        }
    } catch (Exception $e) {
        // Если БД недоступна, пропускаем динамические услуги
    }
    ?>
    
    <!-- Бренды -->
    <url>
        <loc>https://elektromir-rostov.ru/brands</loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.8</priority>
    </url>
    
    <!-- О компании -->
    <url>
        <loc>https://elektromir-rostov.ru/about</loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.7</priority>
    </url>
    
    <!-- Контакты -->
    <url>
        <loc>https://elektromir-rostov.ru/contacts</loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.7</priority>
    </url>
    
    <!-- Карьера -->
    <url>
        <loc>https://elektromir-rostov.ru/career</loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.6</priority>
    </url>
    
    <!-- Документы -->
    <url>
        <loc>https://elektromir-rostov.ru/documents</loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.6</priority>
    </url>
    
    <!-- Политика конфиденциальности -->
    <url>
        <loc>https://elektromir-rostov.ru/policy</loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq>yearly</changefreq>
        <priority>0.3</priority>
    </url>
    
</urlset>
