import { defineComponent as v, computed as u, onMounted as g, onBeforeUnmount as _, ref as L, createElementBlock as y, openBlock as h } from "vue";
const x = ["src"], b = /* @__PURE__ */ v({
  __name: "low-code-iframe",
  props: {
    app: {},
    query: {},
    iframeLoading: { type: Boolean }
  },
  emits: ["emit-change", "update:iframeLoading"],
  setup(n, { expose: c, emit: s }) {
    const a = n, r = u(() => {
      if (!a.app) return;
      let e = "";
      const o = "";
      let t = a.query || {};
      return a.app && (t.app = a.app), e = `${o}/api/node-low-code/v1/visitor/views/index?${new URLSearchParams(t).toString()}`, e;
    }), l = s, d = u({
      get: () => a.iframeLoading,
      set: (e) => l("update:iframeLoading", e)
    }), p = (e) => {
      const { emitName: o = "", emitData: t = {} } = e.data || {};
      o === "app-mounted" ? d.value = !1 : l("emit-change", o, t);
    };
    g(() => {
      window.addEventListener("message", p, !1);
    }), _(() => {
      window.removeEventListener("message", p, !1);
    });
    const i = L(null), m = (e) => {
      var o;
      d.value || (o = i.value) != null && o.contentWindow && i.value.contentWindow.postMessage(e);
    };
    c({
      onActivated: () => {
        m({ type: "onActivated" });
      },
      onDeactivated: () => {
        m({ type: "onDeactivated" });
      }
    });
    const w = () => {
      var o, t, f;
      const { origin: e } = new URL(r.value || "", location.origin);
      e && ((f = (t = (o = i.value) == null ? void 0 : o.contentWindow) == null ? void 0 : t.postMessage) == null || f.call(
        t,
        { type: "setProxSsoStatus", data: { visible: !0, parentHref: location.href } },
        e
      ));
    };
    return (e, o) => (h(), y("iframe", {
      class: "low-code-iframe",
      id: "low-code-iframe",
      src: r.value,
      frameborder: "0",
      sandbox: "allow-same-origin allow-scripts allow-forms allow-modals allow-popups allow-downloads allow-top-navigation",
      ref_key: "lowCodeRef",
      ref: i,
      onLoad: w
    }, null, 40, x));
  }
}), C = (n, c) => {
  const s = n.__vccOpts || n;
  for (const [a, r] of c)
    s[a] = r;
  return s;
}, B = /* @__PURE__ */ C(b, [["__scopeId", "data-v-c5870bec"]]);
export {
  B as LowCode
};
