import * as React from 'react';
import { getCursorPositionOverElement } from "../utils/editor.js";
import { sendEventPostMessage } from "./usePostMessageAPI.js";
const usePCEditorBlockMouseEvents = (arrayIndex, element) => {
    const onMouseUp = React.useCallback((e) => {
        e.stopPropagation();
        if (element) {
            const rect = element.getClientRects().item(0);
            if (rect) {
                const position = getCursorPositionOverElement(rect, e);
                sendEventPostMessage('ON_MOUSE_UP', { path: arrayIndex, rect, position });
            }
        }
    }, [arrayIndex, element]);
    const onMouseMove = React.useCallback((e) => {
        e.stopPropagation();
        if (element) {
            const rect = element.getClientRects().item(0);
            if (rect) {
                const position = getCursorPositionOverElement(rect, e);
                sendEventPostMessage('ON_HOVER_BLOCK', { rect, position });
                sendEventPostMessage('ON_MOUSE_MOVE', { x: e.clientX, y: e.clientY });
            }
        }
    }, [element]);
    const onMouseLeave = React.useCallback(() => {
        if (element) {
            const rect = element.getClientRects().item(0);
            if (rect) {
                sendEventPostMessage('ON_HOVER_BLOCK', {});
            }
        }
    }, [element]);
    const onClick = React.useCallback((e) => {
        e.stopPropagation();
        if (element) {
            sendEventPostMessage('ON_CLICK_BLOCK', { path: arrayIndex });
        }
    }, [arrayIndex, element]);
    return {
        onClick,
        onMouseMove,
        onMouseUp,
        onMouseLeave,
        'data-editor-item': true,
    };
};
export default usePCEditorBlockMouseEvents;
//# sourceMappingURL=usePCEditorBlockMouseEvents.js.map
