<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
        http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">

    <!-- ===== Halaman Statis ===== -->
    
    <!-- Homepage -->
    <url>
        <loc>https://capecut.store/</loc>
        <lastmod>2026-09-02</lastmod>
        <changefreq>daily</changefreq>
        <priority>1.0</priority>
    </url>

    <!-- Halaman Produk (order) -->
    <url>
        <loc>https://capecut.store/order</loc>
        <changefreq>weekly</changefreq>
        <priority>0.9</priority>
    </url>

    <!-- Riwayat Pesanan -->
    <url>
        <loc>https://capecut.store/history</loc>
        <changefreq>weekly</changefreq>
        <priority>0.7</priority>
    </url>

    <!-- Cek Order -->
    <url>
        <loc>https://capecut.store/check-order</loc>
        <changefreq>weekly</changefreq>
        <priority>0.7</priority>
    </url>

    <!-- Kontak -->
    <url>
        <loc>https://capecut.store/contact</loc>
        <lastmod>2026-09-02</lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.8</priority>
    </url>

    <!-- Invoice -->
    <url>
        <loc>https://capecut.store/invoice</loc>
        <changefreq>never</changefreq>
        <priority>0.5</priority>
    </url>

    <!-- ===== Halaman Dinamis (Produk dari API Rifanat) ===== -->
    <!-- Produk akan di-generate secara otomatis oleh PHP -->
    <?php
    // Ambil semua produk dari API Rifanat
    require_once 'config.php';
    require_once 'functions.php';
    
    $products = get_products();
    $base_url = 'https://capecut.store';
    $today = date('Y-m-d');
    
    if (!empty($products)):
        foreach ($products as $product):
            $slug = urlencode($product['slug']);
            $lastmod = !empty($product['updated_at']) ? date('Y-m-d', strtotime($product['updated_at'])) : $today;
    ?>
    <url>
        <loc><?= $base_url ?>/order?slug=<?= htmlspecialchars($slug) ?></loc>
        <lastmod><?= $lastmod ?></lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.8</priority>
    </url>
    <?php 
        endforeach;
    endif;
    ?>

</urlset>