<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    <!-- Ana Sayfa -->
    <url>
        <loc>https://arespak.com/</loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq>daily</changefreq>
        <priority>1.0</priority>
    </url>
    
    <!-- Hakkımızda -->
    <url>
        <loc>https://arespak.com/about.php</loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.8</priority>
    </url>
    
    <!-- Ürünler Ana Sayfa -->
    <url>
        <loc>https://arespak.com/products.php</loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.9</priority>
    </url>
    
    <!-- İletişim -->
    <url>
        <loc>https://arespak.com/contact.php</loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.7</priority>
    </url>
    
    <!-- Teklif Al -->
    <url>
        <loc>https://arespak.com/quote.php</loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.6</priority>
    </url>
    
    <!-- Hizmetler -->
    <url>
        <loc>https://arespak.com/services.php</loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.7</priority>
    </url>
    
    <?php
    // Veritabanı bağlantısı
    require_once 'includes/config.php';
    
    try {
        // Aktif kategorileri ekle
        $stmt = $pdo->query("SELECT slug, updated_at FROM categories WHERE is_active = 1");
        $categories = $stmt->fetchAll();
        
        foreach ($categories as $category) {
            $lastmod = $category['updated_at'] ? date('Y-m-d', strtotime($category['updated_at'])) : date('Y-m-d');
            echo "\n    <url>";
            echo "\n        <loc>https://arespak.com/products.php?category=" . htmlspecialchars($category['slug']) . "</loc>";
            echo "\n        <lastmod>" . $lastmod . "</lastmod>";
            echo "\n        <changefreq>weekly</changefreq>";
            echo "\n        <priority>0.8</priority>";
            echo "\n    </url>";
        }
        
        // Aktif ürünleri ekle
        $stmt = $pdo->query("
            SELECT p.slug, p.updated_at, c.slug as category_slug 
            FROM products p 
            LEFT JOIN categories c ON p.category_id = c.id 
            WHERE p.is_active = 1 AND c.is_active = 1
        ");
        $products = $stmt->fetchAll();
        
        foreach ($products as $product) {
            $lastmod = $product['updated_at'] ? date('Y-m-d', strtotime($product['updated_at'])) : date('Y-m-d');
            echo "\n    <url>";
            echo "\n        <loc>https://arespak.com/product-detail.php?slug=" . htmlspecialchars($product['slug']) . "</loc>";
            echo "\n        <lastmod>" . $lastmod . "</lastmod>";
            echo "\n        <changefreq>monthly</changefreq>";
            echo "\n        <priority>0.6</priority>";
            echo "\n    </url>";
        }
        
        // Aktif sayfaları ekle
        $stmt = $pdo->query("SELECT slug, updated_at FROM pages WHERE is_active = 1");
        $pages = $stmt->fetchAll();
        
        foreach ($pages as $page) {
            $lastmod = $page['updated_at'] ? date('Y-m-d', strtotime($page['updated_at'])) : date('Y-m-d');
            echo "\n    <url>";
            echo "\n        <loc>https://arespak.com/" . htmlspecialchars($page['slug']) . ".php</loc>";
            echo "\n        <lastmod>" . $lastmod . "</lastmod>";
            echo "\n        <changefreq>monthly</changefreq>";
            echo "\n        <priority>0.5</priority>";
            echo "\n    </url>";
        }
        
    } catch(PDOException $e) {
        // Hata durumunda sadece statik sayfalar
    }
    ?>
    
</urlset> 