/**
 * EN: next-intl configuration
 * VI: Cấu hình next-intl
 */

import { getRequestConfig } from 'next-intl/server';
import { defaultLocale, isValidLocale } from './i18n/config';

export default getRequestConfig(async ({ locale }) => {
  // EN: Validate locale, fallback to default if invalid or undefined
  // VI: Validate locale, fallback về default nếu không hợp lệ hoặc undefined
  const validLocale = locale && isValidLocale(locale) ? locale : defaultLocale;

  return {
    locale: validLocale,
    messages: (await import(`./src/i18n/messages/${validLocale}.json`)).default,
    // EN: Enable fallback to default locale
    // VI: Bật fallback về default locale
    fallbackLocale: defaultLocale,
    // EN: Disable environment fallback warnings in production
    // VI: Tắt warnings environment fallback trong production
    nowarn: process.env.NODE_ENV === 'production',
  };
});