'use client';


import { MessageKey } from "../@intlayer/editor-react/dist/esm/editor/dist/esm/messagesKeys.mjs";
import { useCommunicator } from "../@intlayer/editor-react/dist/esm/CommunicatorContext.mjs";
import { useEditorEnabled } from "../@intlayer/editor-react/dist/esm/EditorEnabledContext.mjs";
import { useFocusDictionary } from "../@intlayer/editor-react/dist/esm/FocusDictionaryContext.mjs";
import { useIntlayerContext } from "../client/IntlayerProvider.mjs";
import { NodeType } from "../@intlayer/types/dist/esm/nodeType.mjs";
import { isSameKeyPath } from "../@intlayer/core/dist/esm/utils/isSameKeyPath.mjs";
import { ContentSelector } from "../UI/ContentSelector.mjs";
import { useCallback, useMemo } from "react";
import { jsx } from "react/jsx-runtime";

//#region ../react-intlayer/dist/esm/editor/ContentSelectorWrapper.mjs
const ContentSelectorWrapperContent = ({ children, dictionaryKey, keyPath }) => {
	const { focusedContent, setFocusedContent } = useFocusDictionary();
	const { postMessage, senderId } = useCommunicator();
	const filteredKeyPath = useMemo(() => keyPath.filter((key) => key.type !== NodeType.Translation), [keyPath]);
	return /* @__PURE__ */ jsx(ContentSelector, {
		onPress: useCallback(() => setFocusedContent({
			dictionaryKey,
			keyPath: filteredKeyPath
		}), [dictionaryKey, filteredKeyPath]),
		onHover: useCallback(() => postMessage({
			type: `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,
			data: {
				dictionaryKey,
				keyPath: filteredKeyPath
			},
			senderId
		}), [dictionaryKey, filteredKeyPath]),
		onUnhover: useCallback(() => postMessage({
			type: `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,
			data: null,
			senderId
		}), [senderId]),
		isSelecting: useMemo(() => (focusedContent?.dictionaryKey === dictionaryKey && (focusedContent?.keyPath?.length ?? 0) > 0 && isSameKeyPath(focusedContent?.keyPath ?? [], filteredKeyPath)) ?? false, [
			focusedContent,
			filteredKeyPath,
			dictionaryKey
		]),
		children
	});
};
const ContentSelectorRenderer = ({ children,...props }) => {
	const { enabled } = useEditorEnabled();
	const { disableEditor } = useIntlayerContext();
	if (enabled && !disableEditor) return /* @__PURE__ */ jsx(ContentSelectorWrapperContent, {
		...props,
		children
	});
	return children;
};

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