import { getRequestConfig } from "next-intl/server";

import { getSiteSettings } from "@/lib/app-config";
import { isSupportedLocale } from "@/lib/locale";

export default getRequestConfig(async ({ requestLocale }) => {
  const siteSettings = await getSiteSettings();
  const requestedLocale = await requestLocale;
  const locale =
    isSupportedLocale(requestedLocale)
      ? requestedLocale
      : siteSettings.defaultLocale;

  return {
    locale,
    messages: (await import(`../messages/${locale}.json`)).default,
  };
});
