<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
        xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
        xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"
        xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0">
    
    <!-- Homepage -->
    <url>
        <loc>https://damacars.com.cy/</loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq>daily</changefreq>
        <priority>1.0</priority>
        <image:image>
            <image:loc>https://damacars.com.cy/images/logo.png</image:loc>
            <image:title>DamaCars Cyprus Logo</image:title>
        </image:image>
    </url>
    
    <!-- Cars Listing Page -->
    <url>
        <loc>https://damacars.com.cy/#cars</loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq>daily</changefreq>
        <priority>0.9</priority>
    </url>
    
    <!-- Contact Page -->
    <url>
        <loc>https://damacars.com.cy/#contact</loc>
        <lastmod><?php echo date('Y-m-d'); ?></lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.8</priority>
    </url>
    
    <?php
    // Dynamic car pages
    $cars_file = 'cars_data.json';
    if (file_exists($cars_file)) {
        $cars = json_decode(file_get_contents($cars_file), true);
        foreach ($cars as $car) {
            $car_url = 'https://damacars.com.cy/?car_id=' . $car['id'];
            $car_image = !empty($car['image']) ? 'https://damacars.com.cy/' . $car['image'] : 'https://damacars.com.cy/images/logo.png';
            ?>
    <url>
        <loc><?php echo $car_url; ?></loc>
        <lastmod><?php echo date('Y-m-d', strtotime($car['created_at'] ?? 'now')); ?></lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.7</priority>
        <image:image>
            <image:loc><?php echo $car_image; ?></image:loc>
            <image:title><?php echo htmlspecialchars($car['title']); ?></image:title>
            <image:caption><?php echo htmlspecialchars($car['description'] ?? ''); ?></image:caption>
        </image:image>
    </url>
    <?php
        }
    }
    ?>
    
</urlset>