'use client';


const require_rolldown_runtime = require('../../../../../../../_virtual/rolldown_runtime.cjs');
const require_CommunicatorContext = require('./CommunicatorContext.cjs');
const require_DictionariesRecordContext = require('./DictionariesRecordContext.cjs');
const require_EditorEnabledContext = require('./EditorEnabledContext.cjs');
const require_ConfigurationContext = require('./ConfigurationContext.cjs');
const require_EditedContentContext = require('./EditedContentContext.cjs');
const require_FocusDictionaryContext = require('./FocusDictionaryContext.cjs');
let react = require("react");
let react_jsx_runtime = require("react/jsx-runtime");

//#region ../react-intlayer/dist/esm/@intlayer/editor-react/dist/esm/EditorProvider.mjs
/**
* This component add all the providers needed by the editor.
* It is used to wrap the application, or the editor to work together.
*/
const EditorProvidersWrapper = ({ children }) => {
	const getEditedContentState = require_EditedContentContext.useGetEditedContentState();
	(0, react.useEffect)(() => {
		getEditedContentState();
	}, []);
	return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_DictionariesRecordContext.DictionariesRecordProvider, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_EditedContentContext.EditedContentProvider, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_FocusDictionaryContext.FocusDictionaryProvider, { children }) }) });
};
/**
* This component check if the editor is enabled to render the editor providers.
*/
const EditorEnabledCheckRenderer = ({ children, fallback }) => {
	const getEditorEnabled = require_EditorEnabledContext.useGetEditorEnabledState();
	const { enabled } = require_EditorEnabledContext.useEditorEnabled();
	(0, react.useEffect)(() => {
		if (enabled) return;
		getEditorEnabled();
	}, [enabled]);
	return enabled ? children : fallback;
};
/**
* This component is used to check if the editor is wrapping the application.
* It avoid to send window.postMessage to the application if the editor is not wrapping the application.
*/
const IframeCheckRenderer = ({ children, fallback }) => {
	const [isInIframe, setIsInIframe] = (0, react.useState)(false);
	(0, react.useEffect)(() => {
		setIsInIframe(window.self !== window.top);
	}, []);
	return isInIframe ? children : fallback;
};
const EditorProvider = ({ children, configuration,...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_EditorEnabledContext.EditorEnabledProvider, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_ConfigurationContext.ConfigurationProvider, {
	configuration,
	children: props.mode === "editor" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_CommunicatorContext.CommunicatorProvider, {
		...props,
		children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(EditorProvidersWrapper, { children })
	}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IframeCheckRenderer, {
		fallback: children,
		children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_CommunicatorContext.CommunicatorProvider, {
			...props,
			children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(EditorEnabledCheckRenderer, {
				fallback: children,
				children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(EditorProvidersWrapper, { children })
			})
		})
	})
}) });

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