'use client';


import { setLocaleInStorage } from "./useLocaleStorage.mjs";
import { built_default } from "../@intlayer/config/dist/esm/built.mjs";
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
import { useCallback, useContext } from "react";

//#region ../react-intlayer/dist/esm/client/useLocale.mjs
/**
* On the client side, hook to get the current locale and all related fields
*/
const useLocale = ({ isCookieEnabled, onLocaleChange } = {}) => {
	const { defaultLocale, locales: availableLocales } = built_default?.internationalization ?? {};
	const { locale, setLocale: setLocaleState, isCookieEnabled: isCookieEnabledContext } = useContext(IntlayerClientContext);
	return {
		locale,
		defaultLocale,
		availableLocales,
		setLocale: useCallback((locale$1) => {
			if (!availableLocales?.map(String).includes(locale$1)) {
				console.error(`Locale ${locale$1} is not available`);
				return;
			}
			setLocaleState(locale$1);
			setLocaleInStorage(locale$1, isCookieEnabled ?? isCookieEnabledContext ?? true);
			onLocaleChange?.(locale$1);
		}, [
			availableLocales,
			onLocaleChange,
			setLocaleState
		])
	};
};

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