import { MetadataRoute } from 'next';
import { blogPosts } from '../src/data/blogPosts';
import { technologies } from './technologies/[slug]/data';

/**
 * Sitemap Generator
 * 
 * Standard Next.js 15 App Router sitemap generation.
 * This file dynamically generates /sitemap.xml
 */
export default function sitemap(): MetadataRoute.Sitemap {
    const baseUrl = process.env.NEXT_PUBLIC_BASE_URL || 'https://mintel.me';

    // 1. Core Pages
    const routes = [
        '',
        '/about',
        '/blog',
        '/case-studies',
        '/case-studies/klz-cables',
        '/contact',
        '/websites',
    ].map((route) => ({
        url: `${baseUrl}${route}`,
        lastModified: new Date(),
        changeFrequency: 'monthly' as const,
        priority: route === '' ? 1.0 : 0.8,
    }));

    // 2. Dynamic Blog Posts
    const blogRoutes = blogPosts.map((post) => ({
        url: `${baseUrl}/blog/${post.slug}`,
        lastModified: new Date(post.date),
        changeFrequency: 'monthly' as const,
        priority: 0.7,
    }));

    // 3. Technology Detail Pages
    const techRoutes = Object.keys(technologies).map((slug) => ({
        url: `${baseUrl}/technologies/${slug}`,
        lastModified: new Date(),
        changeFrequency: 'monthly' as const,
        priority: 0.6,
    }));

    // 4. Tag Pages
    const allTags = [...new Set(blogPosts.flatMap((post) => post.tags))];
    const tagRoutes = allTags.map((tag) => ({
        url: `${baseUrl}/tags/${tag}`,
        lastModified: new Date(),
        changeFrequency: 'weekly' as const,
        priority: 0.3,
    }));

    return [...routes, ...blogRoutes, ...techRoutes, ...tagRoutes];
}
