'use client';


const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.cjs');
const require_built = require('../@intlayer/config/dist/esm/built.cjs');
const require_DictionariesRecordContext = require('../@intlayer/editor-react/dist/esm/DictionariesRecordContext.cjs');
const require_EditorEnabledContext = require('../@intlayer/editor-react/dist/esm/EditorEnabledContext.cjs');
const require_EditorProvider = require('../@intlayer/editor-react/dist/esm/EditorProvider.cjs');
const require_useCrossURLPathState = require('../@intlayer/editor-react/dist/esm/useCrossURLPathState.cjs');
const require_useIframeClickInterceptor = require('../@intlayer/editor-react/dist/esm/useIframeClickInterceptor.cjs');
const require_index = require('../@intlayer/unmerged-dictionaries-entry/dist/esm/index.cjs');
let react = require("react");
let react_jsx_runtime = require("react/jsx-runtime");

//#region ../react-intlayer/dist/esm/editor/IntlayerEditorProvider.mjs
const IntlayerEditorHooksEnabled = () => {
	/**
	* URL Messages
	*/
	require_useCrossURLPathState.useCrossURLPathSetter();
	/**
	* Click Messages
	*/
	require_useIframeClickInterceptor.useIframeClickInterceptor();
	/**
	* Sent local dictionaries to editor
	*/
	const { setLocaleDictionaries } = require_DictionariesRecordContext.useDictionariesRecordActions();
	(0, react.useEffect)(() => {
		const unmergedDictionaries = require_index.getUnmergedDictionaries();
		setLocaleDictionaries(Object.fromEntries(Object.values(unmergedDictionaries).flat().map((dictionary) => [dictionary.localId, dictionary])));
	}, []);
	return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, {});
};
const { editor } = require_built.built_default ?? {};
const IntlayerEditorHook = () => {
	const { enabled } = require_EditorEnabledContext.useEditorEnabled();
	return enabled ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IntlayerEditorHooksEnabled, {}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, {});
};
const IntlayerEditorProvider = ({ children }) => {
	return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_EditorProvider.EditorProvider, {
		postMessage: (data) => {
			if (typeof window === "undefined") return;
			if (!editor) return;
			if (!(window.self !== window.top)) return;
			if (editor.applicationURL.length > 0) window?.postMessage(data, editor.applicationURL);
			if (editor.editorURL.length > 0) window.parent?.postMessage(data, editor.editorURL);
			if (editor.cmsURL.length > 0) window.parent?.postMessage(data, editor.cmsURL);
		},
		allowedOrigins: [
			editor?.editorURL,
			editor?.cmsURL,
			editor?.applicationURL
		].filter(Boolean),
		mode: "client",
		configuration: require_built.built_default,
		children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(IntlayerEditorHook, {}), children]
	});
};

//#endregion
exports.IntlayerEditorProvider = IntlayerEditorProvider;
//# sourceMappingURL=IntlayerEditorProvider.cjs.map