import type { Metadata } from "next";
import { notFound } from "next/navigation";
import { LocaleProvider } from "../context/LocaleContext";
import type { Locale } from "../context/LocaleContext";
import { getThemeMessages } from "@/app/lib/theme-data";
import RouteAwareNavbar from "../components/RouteAwareNavbar";
import SetLangAttr from "../components/SetLangAttr";

const LOCALES: Locale[] = ["zh", "en"];

export const metadata: Metadata = {
  title: "游牧中国 NomadCNA - 数字游民生活操作系统",
  description:
    "数字游民的一站式生活操作系统：城市决策、税务签证、智能匹配、赏金任务。从 Free 到 Pro，开启你的游牧人生",
};

export function generateStaticParams() {
  return LOCALES.map((locale) => ({ locale }));
}

export default async function LocaleLayout({
  children,
  params,
}: {
  children: React.ReactNode;
  params: Promise<{ locale: string }>;
}) {
  const { locale } = await params;
  if (!LOCALES.includes(locale as Locale)) {
    notFound();
  }

  const messages = await getThemeMessages(locale as Locale);

  return (
    <LocaleProvider locale={locale as Locale} messages={messages}>
      <SetLangAttr />
      <RouteAwareNavbar />
      {children}
    </LocaleProvider>
  );
}
