'use client';


import { CommunicatorProvider } from "./CommunicatorContext.mjs";
import { DictionariesRecordProvider } from "./DictionariesRecordContext.mjs";
import { EditorEnabledProvider, useEditorEnabled, useGetEditorEnabledState } from "./EditorEnabledContext.mjs";
import { ConfigurationProvider } from "./ConfigurationContext.mjs";
import { EditedContentProvider, useGetEditedContentState } from "./EditedContentContext.mjs";
import { FocusDictionaryProvider } from "./FocusDictionaryContext.mjs";
import { useEffect, useState } from "react";
import { jsx } from "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 = useGetEditedContentState();
	useEffect(() => {
		getEditedContentState();
	}, []);
	return /* @__PURE__ */ jsx(DictionariesRecordProvider, { children: /* @__PURE__ */ jsx(EditedContentProvider, { children: /* @__PURE__ */ jsx(FocusDictionaryProvider, { children }) }) });
};
/**
* This component check if the editor is enabled to render the editor providers.
*/
const EditorEnabledCheckRenderer = ({ children, fallback }) => {
	const getEditorEnabled = useGetEditorEnabledState();
	const { enabled } = useEditorEnabled();
	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] = useState(false);
	useEffect(() => {
		setIsInIframe(window.self !== window.top);
	}, []);
	return isInIframe ? children : fallback;
};
const EditorProvider = ({ children, configuration,...props }) => /* @__PURE__ */ jsx(EditorEnabledProvider, { children: /* @__PURE__ */ jsx(ConfigurationProvider, {
	configuration,
	children: props.mode === "editor" ? /* @__PURE__ */ jsx(CommunicatorProvider, {
		...props,
		children: /* @__PURE__ */ jsx(EditorProvidersWrapper, { children })
	}) : /* @__PURE__ */ jsx(IframeCheckRenderer, {
		fallback: children,
		children: /* @__PURE__ */ jsx(CommunicatorProvider, {
			...props,
			children: /* @__PURE__ */ jsx(EditorEnabledCheckRenderer, {
				fallback: children,
				children: /* @__PURE__ */ jsx(EditorProvidersWrapper, { children })
			})
		})
	})
}) });

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