import { render as m, defineComponent as P, createVNode as p, mergeProps as k, h as N } from "vue";
import { Modal as $ } from "@aplus-frontend/antdv";
import { isNumeric as h } from "@aplus-frontend/utils";
import { omit as E } from "lodash-unified";
import { getTopWindow as F } from "../../utils/index.mjs";
import { globalConfigCached as s, ConfigProvider as L } from "../../config-provider/config-provider.mjs";
import { getContainerDom as C, getModalGlobalAppContext as M } from "./util.mjs";
const W = (t) => {
  let n, r;
  const i = (e) => e ? `${s.value.namespace}-ap-modal-${e}` : `${s.value.namespace}-ap-modal`, {
    destroyOnClose: d = !0,
    wrapperOffset: o = !1,
    wrapperFullHeight: c = !1
  } = t;
  function l() {
    n && n(!1), setTimeout(() => {
      m(null, a), a.parentElement?.removeChild(a);
    }, 500);
  }
  function g() {
    n && n(!0);
  }
  function f() {
    n && n(!1);
  }
  function v(e) {
    r && r(e);
  }
  const x = /* @__PURE__ */ P({
    data() {
      return {
        open: d,
        props: t
      };
    },
    created() {
      n = (e) => {
        this.open = e;
      }, r = (e) => {
        this.props = {
          ...this.props,
          ...e
        };
      };
    },
    methods: {
      async handleCancel() {
        if (this.props?.onCancel) {
          const e = this.props?.content?.component?.exposed ?? void 0;
          await this.props?.onCancel(e);
        }
        d ? l() : f();
      },
      async handleOk() {
        try {
          if (r({
            confirmLoading: !0
          }), this.props?.onOk) {
            const e = this.props?.content?.component?.exposed ?? void 0;
            await this.props.onOk(e);
          }
          r({
            confirmLoading: !1
          }), d ? l() : f();
        } catch {
          r({
            confirmLoading: !1
          });
        }
      },
      handleFooter(e) {
        return t?.footer !== void 0 ? typeof t.footer == "function" ? t.footer({
          ...e,
          contentExposed: this.props?.content?.component?.exposed ?? void 0
        }) : t.footer : e?.originNode;
      }
    },
    render() {
      const e = E(this.props, ["onCancel", "onOk", "open", "onUpdate:open", "getContainer", "icon", "footer"]);
      return p(L, s.value, {
        default: () => [p($, k({
          class: {
            [i()]: !0,
            [i("wrapper")]: o
          },
          centered: !0
        }, e, {
          open: this.open,
          onCancel: this.handleCancel,
          onOk: this.handleOk,
          footer: this?.handleFooter
        }), {
          default: () => [p("div", {
            class: {
              [i("body-wrapper")]: o
            },
            style: {
              maxHeight: o !== !1 ? `calc(100vh - ${(o === !0 ? 100 : h(o) ? Number(o) : 100) * 2}px)` : void 0,
              height: c === !0 ? `calc(100vh - ${(o === !0 ? 100 : h(o) ? Number(o) : 100) * 2}px)` : void 0,
              overflowY: o !== !1 || c === !0 ? "auto" : void 0
            }
          }, [p("div", {
            class: i("body-wrapper-content"),
            style: {
              height: c === !0 ? "100%" : void 0
            }
          }, [this.props?.content])])]
        })]
      });
    }
  }), y = C(s?.value?.getPopupContainer), w = C(t.getContainer), O = y || w || F().document.body, a = document.createElement("div");
  O.appendChild(a);
  const u = N(x), b = M();
  return u.appContext = t.appContext || b || u.appContext, m(u, a), {
    destroy: l,
    update: v,
    open: g,
    close: f
  };
};
export {
  W as createModal
};
