"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const Vue = require("vue");
const RiskSchRenderer = require("./RiskSchRenderer.vue.js");
;/* empty css                                                  */
;/* empty css                                                        */
;/* empty css                                                   */
;/* empty css                                                  */
;/* empty css                                                     */
;/* empty css                                                    */
;/* empty css                                                               */
;/* empty css                                                     */
;/* empty css                                                   */
;/* empty css                                                    */
let currentDialogInstance = null;
let isCleaningUp = false;
const cleanupDialog = () => {
  if (isCleaningUp) return;
  isCleaningUp = true;
  setTimeout(() => {
    var _a;
    try {
      if ((_a = currentDialogInstance == null ? void 0 : currentDialogInstance.container) == null ? void 0 : _a.parentNode) {
        currentDialogInstance.container.parentNode.removeChild(
          currentDialogInstance.container
        );
      }
      if (currentDialogInstance == null ? void 0 : currentDialogInstance.vnode) {
        Vue.render(null, currentDialogInstance.container);
      }
      currentDialogInstance = null;
    } catch (error) {
      console.error("Dialog cleanup error:", error);
    } finally {
      isCleaningUp = false;
    }
  }, 300);
};
function openRiskSch(option, instance, ctx) {
  return new Promise((resolve, reject) => {
    const container = document.createElement("div");
    document.body.appendChild(container);
    const vnode = Vue.createVNode(RiskSchRenderer.default, {
      modelValue: true,
      ...option,
      ctx,
      "onUpdate:modelValue": (val) => {
        if (!val) {
          cleanupDialog();
        }
      },
      onConfirm: (data) => {
        cleanupDialog();
        resolve(data);
      },
      onCancel: () => {
        cleanupDialog();
        reject(new Error("用户取消"));
      }
    });
    vnode.appContext = instance.appContext;
    Vue.render(vnode, container);
    currentDialogInstance = { vnode, container };
  });
}
exports.openRiskSch = openRiskSch;
