import configuration from "@intlayer/config/built";
import { getLocaleFromStorage, localeDetector } from "@intlayer/core";
import { Locales } from "@intlayer/types";
import { cookies, headers } from "next/headers.js";

//#region src/server/getLocale.ts
const getLocale = async () => {
	const defaultLocale = configuration?.internationalization?.defaultLocale ?? Locales.ENGLISH;
	const headersList = await headers();
	const cookiesList = await cookies();
	const storedLocale = getLocaleFromStorage({
		getCookie: (name) => cookiesList.get(name)?.value ?? null,
		getHeader: (name) => headersList.get(name) ?? null
	});
	if (storedLocale) return storedLocale;
	const negotiatorHeaders = {};
	headersList.forEach((value, key) => {
		negotiatorHeaders[key] = value;
	});
	const userFallbackLocale = localeDetector(negotiatorHeaders);
	if (userFallbackLocale) return userFallbackLocale;
	return defaultLocale;
};

//#endregion
export { getLocale };
//# sourceMappingURL=getLocale.mjs.map