"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const editor_1 = require("../utils/editor.js");
const usePostMessageAPI_1 = require("./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 = (0, editor_1.getCursorPositionOverElement)(rect, e);
                (0, usePostMessageAPI_1.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 = (0, editor_1.getCursorPositionOverElement)(rect, e);
                (0, usePostMessageAPI_1.sendEventPostMessage)('ON_HOVER_BLOCK', { rect, position });
                (0, usePostMessageAPI_1.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) {
                (0, usePostMessageAPI_1.sendEventPostMessage)('ON_HOVER_BLOCK', {});
            }
        }
    }, [element]);
    const onClick = React.useCallback((e) => {
        e.stopPropagation();
        if (element) {
            (0, usePostMessageAPI_1.sendEventPostMessage)('ON_CLICK_BLOCK', { path: arrayIndex });
        }
    }, [arrayIndex, element]);
    return {
        onClick,
        onMouseMove,
        onMouseUp,
        onMouseLeave,
        'data-editor-item': true,
    };
};
exports.default = usePCEditorBlockMouseEvents;
//# sourceMappingURL=usePCEditorBlockMouseEvents.js.map
