import _ from "lodash";
import { isHostAppDataExist, setHostAppData } from "./store.js";
import {
  sendMessageToHost,
  getHostAppData
} from "../message-to-host-app/index.js";
import { bindEvent } from "../host-binding-events/index.js";
const fetchHostAppData = (hostedAppUrl, guestAppId) => {
  const isDataExist = isHostAppDataExist();
  return new Promise((resolve) => {
    if (!_.isEmpty(isDataExist)) {
      resolve();
    } else {
      sendMessageToHost({ guestAppId, message: "ready" }, hostedAppUrl);
      bindEvent(window, "message", getHostAppData(setHostAppData, resolve));
    }
  });
};
export {
  fetchHostAppData
};
