import { call, takeLatest } from "redux-saga/effects";
import { ACTIONS } from "../../data/wait-message/actions.js";
import { CMicroAppGuest } from "../../utils/micro-frontend/guest.js";
import { getLogger } from "../../utils/micro-frontend/index.js";
import { logRecords } from "../../utils/log-records.js";
function* openWaitMessage() {
  try {
    const microApp = yield call(
      CMicroAppGuest.getInstance.bind(CMicroAppGuest)
    );
    const host = yield call(microApp.getHost.bind(microApp));
    if (host) yield call(host.openWaitMessage.bind(host));
  } catch (ex) {
    getLogger().error({
      ...logRecords.WAIT_MSG_OPEN_FAILED,
      exception: ex
    });
  }
}
function* closeWaitMessage() {
  try {
    const microApp = yield call(
      CMicroAppGuest.getInstance.bind(CMicroAppGuest)
    );
    const host = yield call(microApp.getHost.bind(microApp));
    if (host) yield call(host.closeWaitMessage.bind(host));
  } catch (ex) {
    getLogger().error({
      ...logRecords.WAIT_MSG_CLOSE_FAILED,
      exception: ex
    });
  }
}
function* waitMessage() {
  yield takeLatest(ACTIONS.OPEN, openWaitMessage);
  yield takeLatest(ACTIONS.CLOSE, closeWaitMessage);
}
export {
  waitMessage
};
