import type { MetadataRoute } from "next";
import { localizedPath } from "@/lib/routing";
import { siteUrl } from "@/lib/seo";
import { getBlogPosts, getCaseStudies, getIndustries, getProducts, getSolutions } from "@/lib/content";

export const dynamic = "force-static";

const staticPaths = [
  "/",
  "/about",
  "/solutions",
  "/products",
  "/room-designer",
  "/room-designer/app",
  "/industries",
  "/success-stories",
  "/talk-to-akarya",
  "/insights",
  "/privacy-policy"
];

export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
  const [solutions, products, industries, caseStudies, blogPosts] = await Promise.all([
    getSolutions(),
    getProducts(),
    getIndustries(),
    getCaseStudies(),
    getBlogPosts()
  ]);

  const detailPaths = [
    ...solutions.map((item) => `/solutions/${item.slug}`),
    ...products.map((item) => `/products/${item.slug}`),
    ...industries.map((item) => `/industries/${item.slug}`),
    ...caseStudies.map((item) => `/success-stories/${item.slug}`),
    ...blogPosts.map((item) => `/insights/${item.slug}`)
  ];

  return [...staticPaths, ...detailPaths].flatMap((path) => [
    {
      url: `${siteUrl}${localizedPath(path, "en")}`,
      lastModified: new Date(),
      alternates: {
        languages: {
          en: `${siteUrl}${localizedPath(path, "en")}`,
          id: `${siteUrl}${localizedPath(path, "id")}`
        }
      }
    },
    {
      url: `${siteUrl}${localizedPath(path, "id")}`,
      lastModified: new Date(),
      alternates: {
        languages: {
          en: `${siteUrl}${localizedPath(path, "en")}`,
          id: `${siteUrl}${localizedPath(path, "id")}`
        }
      }
    }
  ]);
}
