import { createApp as u } from "vue";
import { ElImageViewer as m } from "element-plus";
import "element-plus/es/components/image-viewer/style/css";
const _ = (n, t) => {
  var e;
  const { __IN_DAS_MICRO_APP: o, __DAS_MAIN_APP_HREF: r } = window;
  if (!o || !r) return;
  const { origin: i } = new URL(r);
  (e = window.top) == null || e.postMessage({ type: n, data: t }, i);
}, a = (n) => {
  const t = document.createElement("div");
  t.classList.add("das-image-viewer-preview-btn-groups");
  const { previewList: o = [], previewBtns: r = [] } = n, i = u(m, {
    urlList: o,
    onClose: () => {
      i.unmount(), document.body.removeChild(t);
    }
  });
  document.body.appendChild(t), i.mount(t), setTimeout(() => {
    const e = document.querySelector(".el-image-viewer__wrapper");
    e == null || e.classList.add("das-image-viewer-preview-btn-groups"), e == null || e.classList.add(...r);
  }, 0);
}, w = "proxy-image-preview", p = {
  sendMessageToMainApp: _,
  // @ts-ignore
  isMicroApp: () => window.__IN_DAS_MICRO_APP && window.top !== window.self,
  addEventFromMicroApp: () => {
    window.addEventListener("message", (n) => {
      const { type: t, data: o } = n.data;
      t === w && a(o);
    });
  }
};
p.addEventFromMicroApp();
const g = () => ({ onPreview: (t) => {
  const { previewList: o = [], previewBtnConfig: r = !0 } = t, e = {
    previewList: o,
    previewBtns: (() => {
      const d = [], s = r;
      if (typeof s == "boolean")
        return s ? ["zoom_in", "zoom_out", "turn_left", "turn_right", "full_screen"] : [];
      for (const c in s)
        s[c] && d.push(c);
      return d;
    })()
  };
  if (!p.isMicroApp()) return a(e);
  p.sendMessageToMainApp(w, e);
} });
export {
  g as useImageViewer
};
