import type { MetadataRoute } from "next";
import { getMergedTools } from "@/lib/dynamicTools";
import { posts } from "@/lib/blog";
import { SITE_URL } from "@/lib/site";

export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
  const base = SITE_URL;
  const tools = await getMergedTools();

  const staticPages = ["", "/tools", "/about", "/contact", "/blog", "/privacy-policy", "/terms-of-service"].map(
    (path) => ({
      url: `${base}${path}`,
      lastModified: new Date(),
    })
  );

  const toolPages = tools.map((t) => ({
    url: `${base}/tools/${t.slug}`,
    lastModified: new Date(),
  }));

  const blogPages = posts.map((p) => ({
    url: `${base}/blog/${p.slug}`,
    lastModified: new Date(p.date),
  }));

  return [...staticPages, ...toolPages, ...blogPages];
}
