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

const locales = ['en', 'de'] as const;

export default getRequestConfig(async ({ requestLocale }) => {
    // `requestLocale` kommt von next-intl (z.B. aus dem [locale]-Segment oder Fallback)
    let locale = await requestLocale;

    console.log('[i18n/request] incoming requestLocale:', locale);

    if (!locale || !locales.includes(locale as (typeof locales)[number])) {
        locale = 'en';
        console.log('[i18n/request] falling back to default locale:', locale);
    }

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