"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sendEventPostMessage = sendEventPostMessage;
exports.listenPostMessageActions = listenPostMessageActions;
exports.useInternalPostMessageAPIListener = useInternalPostMessageAPIListener;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
function sendEventPostMessage(action, data) {
    const message = { action, data };
    window.parent.postMessage(message);
}
function listenPostMessageActions(action, callback) {
    const onMessage = (e) => {
        const message = e.data;
        if ('action' in message && message.action === action) {
            return callback(message.data);
        }
        return undefined;
    };
    window.addEventListener('message', onMessage);
    return () => {
        window.removeEventListener('message', onMessage);
    };
}
function useInternalPostMessageAPIListener(action, callback) {
    React.useEffect(() => {
        return listenPostMessageActions(action, callback);
    }, [action, callback]);
}
//# sourceMappingURL=usePostMessageAPI.js.map
