<?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">
    
    <!-- Ana Sayfa -->
    <url>
        <loc>https://bttedarik.com/</loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq>daily</changefreq>
        <priority>1.0</priority>
    </url>
    
    <!-- Ürünler Sayfası -->
    <url>
        <loc>https://bttedarik.com/products.php</loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq>daily</changefreq>
        <priority>0.9</priority>
    </url>
    
    <!-- Blog Sayfası -->
    <url>
        <loc>https://bttedarik.com/blog.php</loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.8</priority>
    </url>
    
    <!-- İletişim Sayfası -->
    <url>
        <loc>https://bttedarik.com/contact.php</loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.7</priority>
    </url>
    
    <!-- Hakkımızda Sayfası -->
    <url>
        <loc>https://bttedarik.com/about.php</loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.6</priority>
    </url>
    
    <!-- Sepet Sayfası -->
    <url>
        <loc>https://bttedarik.com/cart.php</loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.5</priority>
    </url>
    
    <!-- Ödeme Sayfası -->
    <url>
        <loc>https://bttedarik.com/checkout.php</loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.5</priority>
    </url>
    
    <!-- Kategoriler -->
    <?php
    require_once 'includes/db.php';
    try {
        $stmt = $pdo->query("SELECT * FROM categories WHERE status = 'active'");
        $categories = $stmt->fetchAll();
        
        foreach ($categories as $category) {
            echo '<url>' . "\n";
            echo '<loc>https://bttedarik.com/products.php?category=' . urlencode($category['slug']) . '</loc>' . "\n";
            echo '<lastmod>' . date('Y-m-d') . '</lastmod>' . "\n";
            echo '<changefreq>weekly</changefreq>' . "\n";
            echo '<priority>0.8</priority>' . "\n";
            echo '</url>' . "\n";
        }
    } catch (PDOException $e) {
        // Hata durumunda sessizce devam et
    }
    ?>
    
    <!-- Ürünler -->
    <?php
    try {
        $stmt = $pdo->query("SELECT * FROM products WHERE status = 'active'");
        $products = $stmt->fetchAll();
        
        foreach ($products as $product) {
            echo '<url>' . "\n";
            echo '<loc>https://bttedarik.com/product-detail.php?id=' . $product['id'] . '</loc>' . "\n";
            echo '<lastmod>' . date('Y-m-d', strtotime($product['updated_at'])) . '</lastmod>' . "\n";
            echo '<changefreq>weekly</changefreq>' . "\n";
            echo '<priority>0.7</priority>' . "\n";
            
            // Ürün resmi
            if (!empty($product['image'])) {
                echo '<image:image>' . "\n";
                echo '<image:loc>https://bttedarik.com/assets/images/products/' . htmlspecialchars($product['image']) . '</image:loc>' . "\n";
                echo '<image:title>' . htmlspecialchars($product['name']) . '</image:title>' . "\n";
                echo '<image:caption>' . htmlspecialchars($product['description']) . '</image:caption>' . "\n";
                echo '</image:image>' . "\n";
            }
            
            echo '</url>' . "\n";
        }
    } catch (PDOException $e) {
        // Hata durumunda sessizce devam et
    }
    ?>
    
    <!-- Blog Yazıları -->
    <?php
    try {
        $stmt = $pdo->query("SELECT * FROM blog_posts WHERE status = 'published'");
        $blog_posts = $stmt->fetchAll();
        
        foreach ($blog_posts as $post) {
            echo '<url>' . "\n";
            echo '<loc>https://bttedarik.com/blog-detail.php?id=' . $post['id'] . '</loc>' . "\n";
            echo '<lastmod>' . date('Y-m-d', strtotime($post['updated_at'])) . '</lastmod>' . "\n";
            echo '<changefreq>monthly</changefreq>' . "\n";
            echo '<priority>0.6</priority>' . "\n";
            echo '</url>' . "\n";
        }
    } catch (PDOException $e) {
        // Hata durumunda sessizce devam et
    }
    ?>
    
</urlset>

