import { toError as m, buildRenderV2Key as s, buildLegacyRenderKey as c, buildUnmountKey as f, buildObservableKey as l, buildLegacyRenderOptions as a } from "../mfRuntimeUtils/mfRuntimeUtils.js";
function u() {
  return window;
}
function y(e) {
  if (typeof e != "object" || e === null)
    return !1;
  const n = e;
  return typeof n.subscribe == "function" && typeof n.unsubscribe == "function" && typeof n.tryAgain == "function";
}
function F(e, n) {
  const o = u(), r = o[s(e, n)];
  if (typeof r == "function")
    return r;
  const i = o[c(e, n)];
  if (typeof i != "function")
    return;
  const d = i;
  return (t) => {
    d(
      t.containerId,
      t.environment,
      t.hostTools,
      t.currentLocale,
      t.hostTheme,
      t.axiosOperation,
      t.formatter,
      t.dynamicMFStore,
      t.windowTools,
      a(t)
    );
  };
}
function b(e, n) {
  const o = u()[f(e, n)];
  return typeof o == "function" ? o : void 0;
}
function I(e, n) {
  const o = u()[l(e, n)];
  return y(o) ? o : void 0;
}
function v(e, n, o) {
  u()[l(e, n)] = o;
}
function M(e, n, o) {
  let r;
  const i = b(n, e.moduleId);
  if (i)
    try {
      i(e.divContainerId);
    } catch (d) {
      r = m(
        d,
        `Failed to unmount MF "${n}/${e.moduleId}" during cleanup`
      ), console.error(r);
    }
  return o || (document.getElementById(e.scriptId)?.remove(), delete u()[s(n, e.moduleId)], delete u()[c(n, e.moduleId)], delete u()[f(n, e.moduleId)], delete u()[l(n, e.moduleId)]), r;
}
export {
  M as cleanUpMFInstance,
  I as getMFObservableLoader,
  F as getMFRenderFunction,
  b as getMFUnmountFunction,
  v as setMFObservableLoader
};
