import { built_default } from "../@intlayer/config/dist/esm/built.mjs";
import { getServerContext } from "./serverContext.mjs";
import { IntlayerServerContext } from "./IntlayerServerProvider.mjs";
import { useDictionary } from "./useDictionary.mjs";
import { useLoadDynamic } from "./useLoadDynamic.mjs";

//#region ../react-intlayer/dist/esm/server/useDictionaryDynamic.mjs
/**
* On the server side, Hook that transform a dictionary and return the content
*
* If the locale is not provided, it will use the locale from the server context
*/
const useDictionaryDynamic = (dictionaryPromise, key, locale) => {
	const localeTarget = locale ?? getServerContext(IntlayerServerContext) ?? built_default?.internationalization.defaultLocale;
	return useDictionary(useLoadDynamic(`${String(key)}.${localeTarget}`, dictionaryPromise[localeTarget]?.()), localeTarget);
};

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