import { key } from './constants';
import { isMobileApp, messageBrokerFacade as mobileAppFacade, } from './helpers/mobileApp';
import { isVttView, messageBrokerFacade as vttViewFacade, } from './helpers/vttView';
export const getMessageBroker = () => new Promise((resolve, reject) => (function findMessageBroker() {
    if (process.env.NODE_ENV === 'development') {
        console.log(`looking for window[${String(key)}]`);
    }
    const messageBroker = isMobileApp
        ? mobileAppFacade
        : isVttView
            ? vttViewFacade
            : window[key];
    if (messageBroker !== undefined) {
        if (process.env.NODE_ENV === 'development') {
            console.log(`found window[${String(key)}]:`, window[key]);
        }
        if (!window[key]) {
            window[key] = messageBroker;
        }
        resolve(messageBroker);
        return;
    }
    if (document.readyState === 'complete' ||
        document.readyState === 'interactive') {
        if (process.env.NODE_ENV === 'development') {
            console.log(`never found window[${String(key)}]`);
        }
        reject(new Error('A message broker was never instantiated in this document'));
        return;
    }
    setTimeout(findMessageBroker, 100);
})());
//# sourceMappingURL=getMessageBroker.js.map