const commonPostMessage = function (messageObj) {
    const obj = { ...messageObj, urlParams: window.location.search, origin: "template" }
    window.parent.postMessage(obj, '*');
};

export const getDPEData = async function () {
    return new Promise((resolve, reject) => {
        let processed = false;
        let timeoutId = setTimeout(() => {
            if (!processed) {
                window.removeEventListener("message", eventCallback);
                reject("timeout")
            }
        }, 5000);
        const eventCallback = (e) => {
            console.log("==3==")
            processed = true;
            window.removeEventListener("message", eventCallback);
            clearTimeout(timeoutId);
            resolve(e)
        }
        console.log("==1==")
        commonPostMessage({ action: "getDPEData", data: window.location.search }); 
        console.log("==2==")
        window.addEventListener("message", eventCallback)
    })
}