'use client';


import { MessageKey } from "./editor/dist/esm/messagesKeys.mjs";
import { useCrossFrameState } from "./useCrossFrameState.mjs";
import { createContext, useContext, useMemo } from "react";
import { jsx } from "react/jsx-runtime";

//#region ../react-intlayer/dist/esm/@intlayer/editor-react/dist/esm/DictionariesRecordContext.mjs
const DictionariesRecordStatesContext = createContext(void 0);
const DictionariesRecordActionsContext = createContext(void 0);
const DictionariesRecordProvider = ({ children }) => {
	const [localeDictionaries, setLocaleDictionaries] = useCrossFrameState(MessageKey.INTLAYER_LOCALE_DICTIONARIES_CHANGED, void 0);
	const stateValue = useMemo(() => ({ localeDictionaries: localeDictionaries ?? {} }), [localeDictionaries]);
	const actionValue = useMemo(() => ({
		setLocaleDictionaries,
		setLocaleDictionary: (dictionary) => {
			if (!dictionary.localId) return;
			setLocaleDictionaries((dictionaries) => ({
				...dictionaries,
				[dictionary.localId]: dictionary
			}));
		}
	}), [setLocaleDictionaries]);
	return /* @__PURE__ */ jsx(DictionariesRecordStatesContext.Provider, {
		value: stateValue,
		children: /* @__PURE__ */ jsx(DictionariesRecordActionsContext.Provider, {
			value: actionValue,
			children
		})
	});
};
const useDictionariesRecordActions = () => useContext(DictionariesRecordActionsContext);
const useDictionariesRecord = () => {
	const actionsContext = useDictionariesRecordActions();
	const statesContext = useContext(DictionariesRecordStatesContext);
	if (!statesContext) throw new Error("useDictionariesRecordStates must be used within a DictionariesRecordProvider");
	return {
		...statesContext,
		...actionsContext
	};
};

//#endregion
export { DictionariesRecordProvider, useDictionariesRecord, useDictionariesRecordActions };
//# sourceMappingURL=DictionariesRecordContext.mjs.map