import * as React from 'react';
import { POST_MESSAGE_SOURCE } from "../common/constants.js";
import { isValidPostMessage } from "../common/postMessage.js";
export function sendEventPostMessage(action, data) {
    const message = { action, data, source: POST_MESSAGE_SOURCE };
    window.parent.postMessage(message, '*');
}
export function listenPostMessageActions(action, callback) {
    const onMessage = (e) => {
        if (!isValidPostMessage(e.data)) {
            return undefined;
        }
        const message = e.data;
        if (message.action === action) {
            return callback(message.data);
        }
        return undefined;
    };
    window.addEventListener('message', onMessage);
    return () => window.removeEventListener('message', onMessage);
}
export function useInternalPostMessageAPIListener(action, callback) {
    React.useEffect(() => {
        return listenPostMessageActions(action, callback);
    }, [action, callback]);
}
//# sourceMappingURL=usePostMessageAPI.js.map
