import { call, takeLatest } from "redux-saga/effects";
import { actions } from "../../data/error/index.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* openErrorToast(action) {
  try {
    const microApp = yield call(
      CMicroAppGuest.getInstance.bind(CMicroAppGuest)
    );
    const host = yield call(microApp.getHost.bind(microApp));
    const message = action?.payload?.description || action?.payload?.messageText;
    if (host && message) yield call(host.openErrorBanner.bind(host), message);
  } catch (ex) {
    getLogger().error({
      ...logRecords.ERR_TOAST_OPEN_FAILED,
      exception: ex
    });
  }
}
function* errorToast() {
  yield takeLatest(actions.set.type, openErrorToast);
}
export {
  errorToast
};
