<?php
require_once 'config.php';

header('Content-Type: application/xml; charset=utf-8');

$base_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'];
$lastmod = date('Y-m-d');

echo '<?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">

    <!-- Ana Sayfa -->
    <url>
        <loc><?= $base_url ?>/</loc>
        <lastmod><?= $lastmod ?></lastmod>
        <changefreq>weekly</changefreq>
        <priority>1.0</priority>
    </url>

    <!-- Hizmetler Sayfası -->
    <url>
        <loc><?= $base_url ?>/#services</loc>
        <lastmod><?= $lastmod ?></lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.9</priority>
    </url>

    <!-- Teknolojiler Sayfası -->
    <url>
        <loc><?= $base_url ?>/#technologies</loc>
        <lastmod><?= $lastmod ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.8</priority>
    </url>

    <!-- Portfolyo Sayfası -->
    <url>
        <loc><?= $base_url ?>/#portfolio</loc>
        <lastmod><?= $lastmod ?></lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.8</priority>
    </url>

    <!-- Paketler Sayfası -->
    <url>
        <loc><?= $base_url ?>/#packages</loc>
        <lastmod><?= $lastmod ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.7</priority>
    </url>

    <!-- İletişim Sayfası -->
    <url>
        <loc><?= $base_url ?>/#contact</loc>
        <lastmod><?= $lastmod ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.6</priority>
    </url>

    <?php
    // Hizmetler için dinamik URL'ler
    if (!empty($services)) {
        foreach ($services as $service) {
            $service_slug = strtolower(str_replace([' ', '&', '/'], ['-', 'and', '-'], $service['title']));
            echo "\n    <!-- Hizmet: " . htmlspecialchars($service['title']) . " -->\n";
            echo "    <url>\n";
            echo "        <loc>{$base_url}/#services-{$service_slug}</loc>\n";
            echo "        <lastmod>{$lastmod}</lastmod>\n";
            echo "        <changefreq>monthly</changefreq>\n";
            echo "        <priority>0.7</priority>\n";
            echo "    </url>\n";
        }
    }

    // Portfolyo projeleri için dinamik URL'ler
    if (!empty($portfolio)) {
        foreach ($portfolio as $project) {
            $project_slug = strtolower(str_replace([' ', '&', '/'], ['-', 'and', '-'], $project['title']));
            echo "\n    <!-- Proje: " . htmlspecialchars($project['title']) . " -->\n";
            echo "    <url>\n";
            echo "        <loc>{$base_url}/#portfolio-{$project_slug}</loc>\n";
            echo "        <lastmod>{$lastmod}</lastmod>\n";
            echo "        <changefreq>monthly</changefreq>\n";
            echo "        <priority>0.6</priority>\n";
            echo "    </url>\n";
        }
    }
    ?>

</urlset>
