<?xml version="1.0" encoding="UTF-8"?>
<?php
header('Content-Type: application/xml; charset=utf-8');
require_once __DIR__ . '/config/database.php';
require_once __DIR__ . '/includes/functions.php';

$baseUrl = 'https://' . ($_SERVER['HTTP_HOST'] ?? 'localhost');
$currentDate = date('Y-m-d');

$courses = getActiveCourses();
$teamMembers = getTeamMembers();
$blogPosts = getBlogPosts(100);
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    <!-- Static Pages -->
    <url>
        <loc><?= $baseUrl ?>/</loc>
        <lastmod><?= $currentDate ?></lastmod>
        <changefreq>daily</changefreq>
        <priority>1.0</priority>
    </url>
    
    <url>
        <loc><?= $baseUrl ?>/hakkimizda</loc>
        <lastmod><?= $currentDate ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.8</priority>
    </url>
    
    <url>
        <loc><?= $baseUrl ?>/kurslar</loc>
        <lastmod><?= $currentDate ?></lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.9</priority>
    </url>
    
    <url>
        <loc><?= $baseUrl ?>/ekibimiz</loc>
        <lastmod><?= $currentDate ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.7</priority>
    </url>
    
    <url>
        <loc><?= $baseUrl ?>/arac-filomuz</loc>
        <lastmod><?= $currentDate ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.6</priority>
    </url>
    
    <url>
        <loc><?= $baseUrl ?>/galeri</loc>
        <lastmod><?= $currentDate ?></lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.6</priority>
    </url>
    
    <url>
        <loc><?= $baseUrl ?>/sss</loc>
        <lastmod><?= $currentDate ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.7</priority>
    </url>
    
    <url>
        <loc><?= $baseUrl ?>/blog</loc>
        <lastmod><?= $currentDate ?></lastmod>
        <changefreq>daily</changefreq>
        <priority>0.8</priority>
    </url>
    
    <url>
        <loc><?= $baseUrl ?>/iletisim</loc>
        <lastmod><?= $currentDate ?></lastmod>
        <changefreq>yearly</changefreq>
        <priority>0.8</priority>
    </url>
    
    <!-- Location Pages -->
    <url>
        <loc><?= $baseUrl ?>/nilufer-surcu-kursu</loc>
        <lastmod><?= $currentDate ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.9</priority>
    </url>
    
    <url>
        <loc><?= $baseUrl ?>/osmangazi-surcu-kursu</loc>
        <lastmod><?= $currentDate ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.9</priority>
    </url>
    
    <!-- Course Detail Pages -->
    <?php if (!empty($courses)): ?>
        <?php foreach ($courses as $course): ?>
    <url>
        <loc><?= $baseUrl ?>/kurs/<?= $course['id'] ?></loc>
        <lastmod><?= date('Y-m-d', strtotime($course['created_at'] ?? $currentDate)) ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.8</priority>
    </url>
        <?php endforeach; ?>
    <?php endif; ?>
    
    <!-- Team Member Detail Pages -->
    <?php if (!empty($teamMembers)): ?>
        <?php foreach ($teamMembers as $member): ?>
    <url>
        <loc><?= $baseUrl ?>/egitmen/<?= $member['id'] ?></loc>
        <lastmod><?= date('Y-m-d', strtotime($member['created_at'] ?? $currentDate)) ?></lastmod>
        <changefreq>yearly</changefreq>
        <priority>0.6</priority>
    </url>
        <?php endforeach; ?>
    <?php endif; ?>
    
    <!-- Blog Post Detail Pages -->
    <?php if (!empty($blogPosts)): ?>
        <?php foreach ($blogPosts as $post): ?>
    <url>
        <loc><?= $baseUrl ?>/blog/<?= $post['id'] ?></loc>
        <lastmod><?= date('Y-m-d', strtotime($post['created_at'] ?? $currentDate)) ?></lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.7</priority>
    </url>
        <?php endforeach; ?>
    <?php endif; ?>
</urlset>