'use client';


const require_rolldown_runtime = require('../../../../../../../_virtual/rolldown_runtime.cjs');
const require_messagesKeys = require('./editor/dist/esm/messagesKeys.cjs');
const require_useCrossFrameState = require('./useCrossFrameState.cjs');
let react = require("react");
let react_jsx_runtime = require("react/jsx-runtime");

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

//#endregion
exports.DictionariesRecordProvider = DictionariesRecordProvider;
exports.useDictionariesRecord = useDictionariesRecord;
exports.useDictionariesRecordActions = useDictionariesRecordActions;
//# sourceMappingURL=DictionariesRecordContext.cjs.map