"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const lodash_1 = tslib_1.__importDefault(require("lodash"));
const usePCEditorStore_1 = require("./usePCEditorStore.js");
const usePostMessageAPI_1 = require("./usePostMessageAPI.js");
const usePCEditorBlockSelection = (arrayIndex, element) => {
    const { selectedBlock } = (0, usePCEditorStore_1.usePCEditorStore)();
    const onResize = React.useCallback(() => {
        if (element && lodash_1.default.isEqual(selectedBlock, arrayIndex)) {
            const rect = element.getClientRects().item(0);
            if (rect) {
                (0, usePostMessageAPI_1.sendEventPostMessage)('ON_UPDATE_BLOCK_SELECTION', { rect });
            }
        }
    }, [arrayIndex, element, selectedBlock]);
    React.useEffect(() => {
        window.addEventListener('resize', onResize);
        return () => {
            window.removeEventListener('resize', onResize);
        };
    }, [element, onResize]);
    // Update blockBorders when selectedBlock changes
    React.useEffect(() => {
        onResize();
    }, [onResize]);
};
exports.default = usePCEditorBlockSelection;
//# sourceMappingURL=usePCEditorBlockSelection.js.map
