<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    <!-- 首頁 -->
    <url>
        <loc>https://cs-wood.com.tw/</loc>
        <changefreq>daily</changefreq>
        <priority>1.0</priority>
    </url>

    <!-- 關於我們 -->
    <url>
        <loc>https://cs-wood.com.tw/about.php</loc>
        <changefreq>monthly</changefreq>
        <priority>0.8</priority>
    </url>

    <!-- 產品列表頁 -->
    <url>
        <loc>https://cs-wood.com.tw/products.php</loc>
        <changefreq>weekly</changefreq>
        <priority>0.8</priority>
    </url>

    <!-- 聯絡我們 -->
    <url>
        <loc>https://cs-wood.com.tw/contact.php</loc>
        <changefreq>monthly</changefreq>
        <priority>0.8</priority>
    </url>

    <!-- 產品詳情頁 -->
    <?php
    require_once 'includes/config.php';
    require_once 'includes/db.php';

    $db = new Database();
    $conn = $db->getConnection();

    $stmt = $conn->query("
        SELECT id, updated_at 
        FROM products 
        WHERE status = 'active' 
        ORDER BY id DESC
    ");
    
    while ($product = $stmt->fetch(PDO::FETCH_ASSOC)) {
        echo "
    <url>
        <loc>https://cs-wood.com.tw/product.php?id={$product['id']}</loc>
        <lastmod>" . date('Y-m-d', strtotime($product['updated_at'])) . "</lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.6</priority>
    </url>";
    }
    ?>
</urlset>