<?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">

    <!-- Static Pages -->
    <url>
        <loc>https://afwork.oeacnetwork.com/</loc>
        <lastmod>2024-01-01</lastmod>
        <changefreq>daily</changefreq>
        <priority>1.0</priority>
    </url>
    <url>
        <loc>https://afwork.oeacnetwork.com/about.php</loc>
        <lastmod>2024-01-01</lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.8</priority>
    </url>
    <url>
        <loc>https://afwork.oeacnetwork.com/contact.php</loc>
        <lastmod>2024-01-01</lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.8</priority>
    </url>
    <url>
        <loc>https://afwork.oeacnetwork.com/services.php</loc>
        <lastmod>2024-01-01</lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.9</priority>
    </url>
    <url>
        <loc>https://afwork.oeacnetwork.com/hire-talent.php</loc>
        <lastmod>2024-01-01</lastmod>
        <changefreq>daily</changefreq>
        <priority>0.9</priority>
    </url>
    <url>
        <loc>https://afwork.oeacnetwork.com/register.php</loc>
        <lastmod>2024-01-01</lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.7</priority>
    </url>
    <url>
        <loc>https://afwork.oeacnetwork.com/login.php</loc>
        <lastmod>2024-01-01</lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.7</priority>
    </url>

    <!-- Dynamic Freelancer Profiles -->
    <?php
    // Fetch all freelancers for sitemap
    $stmt = db()->query("SELECT id, updated_at FROM users WHERE role = 'freelancer' AND status = 'active'");
    while ($freelancer = $stmt->fetch()) {
        echo "<url>\n";
        echo "    <loc>https://afwork.oeacnetwork.com/freelancer-profile.php?id=" . $freelancer['id'] . "</loc>\n";
        echo "    <lastmod>" . date('Y-m-d', strtotime($freelancer['updated_at'] ?? 'now')) . "</lastmod>\n";
        echo "    <changefreq>weekly</changefreq>\n";
        echo "    <priority>0.6</priority>\n";
        echo "</url>\n";
    }
    
    // Fetch all gigs
    $stmt = db()->query("SELECT id, updated_at FROM gigs WHERE status = 'published'");
    while ($gig = $stmt->fetch()) {
        echo "<url>\n";
        echo "    <loc>https://afwork.oeacnetwork.com/gig-details.php?id=" . $gig['id'] . "</loc>\n";
        echo "    <lastmod>" . date('Y-m-d', strtotime($gig['updated_at'] ?? 'now')) . "</lastmod>\n";
        echo "    <changefreq>weekly</changefreq>\n";
        echo "    <priority>0.6</priority>\n";
        echo "</url>\n";
    }
    ?>
</urlset>