'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
var iconsVue = require('@ant-design/icons-vue');
require('../../../utils/index.cjs');
require('../../../vue-components/index.cjs');
var index$1 = require('../../button/index.cjs');
require('../../locale-provider/index.cjs');
var useConfigInject = require('../../config-provider/src/hooks/useConfigInject.cjs');
var index = require('../style/index.cjs');
var props = require('./props.cjs');
var styleChecker = require('../../../utils/dom/styleChecker.cjs');
var addEventListener = require('../../../utils/event/addEventListener.cjs');
var initDefaultProps = require('../../../utils/vue/initDefaultProps.cjs');
var useLocaleReceiver = require('../../locale-provider/src/useLocaleReceiver.cjs');
var log = require('../../../utils/log.cjs');
var utils = require('../../button/src/utils.cjs');
var _class = require('../../../utils/dom/class.cjs');
var DialogWrap = require('../../../vue-components/vc-dialog/src/DialogWrap.cjs');
var transition = require('../../../vue-components/transition/src/transition.cjs');

let mousePosition;
function getClickPosition(e) {
  mousePosition = {
    x: e.pageX,
    y: e.pageY
  };
  setTimeout(() => mousePosition = null, 100);
}
if (styleChecker.canUseDocElement())
  addEventListener.addEventListenerWrap(document.documentElement, "click", getClickPosition, true);
var AModal = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "AModal",
  test: 1,
  inheritAttrs: false,
  props: initDefaultProps.initDefaultProps(props.modalProps(), {
    width: 520,
    confirmLoading: false,
    okType: "primary"
  }),
  setup(props, {
    emit,
    slots,
    attrs
  }) {
    const [locale] = useLocaleReceiver.useLocaleReceiver("Modal");
    const {
      prefixCls,
      rootPrefixCls,
      direction,
      getPopupContainer
    } = useConfigInject.default("modal", props);
    const [wrapSSR, hashId] = index.default(prefixCls);
    log.devWarning(props.visible === void 0, "Modal", "`visible` will be removed in next major version, please use `open` instead.");
    const handleCancel = (e) => {
      emit("update:visible", false);
      emit("update:open", false);
      emit("cancel", e);
      emit("change", false);
    };
    const handleOk = (e) => {
      emit("ok", e);
    };
    const renderFooter = () => {
      var _a, _b;
      const {
        okText = (_a = slots.okText) == null ? void 0 : _a.call(slots),
        okType,
        cancelText = (_b = slots.cancelText) == null ? void 0 : _b.call(slots),
        confirmLoading
      } = props;
      return vue.createVNode(vue.Fragment, null, [vue.createVNode(index$1.Button, {
        "onClick": handleCancel,
        ...props.cancelButtonProps
      }, {
        default: () => [cancelText || locale.value.cancelText]
      }), vue.createVNode(index$1.Button, {
        ...utils.convertLegacyProps(okType),
        "loading": confirmLoading,
        "onClick": handleOk,
        ...props.okButtonProps
      }, {
        default: () => [okText || locale.value.okText]
      })]);
    };
    return () => {
      var _a, _b;
      const {
        prefixCls: customizePrefixCls,
        visible,
        open,
        wrapClassName,
        centered,
        getContainer,
        closeIcon = (_a = slots.closeIcon) == null ? void 0 : _a.call(slots),
        focusTriggerAfterClose = true,
        ...restProps
      } = props;
      const wrapClassNameExtended = _class.classNames(wrapClassName, {
        [`${prefixCls.value}-centered`]: !!centered,
        [`${prefixCls.value}-wrap-rtl`]: direction.value === "rtl"
      });
      return wrapSSR(vue.createVNode(DialogWrap.default, {
        ...restProps,
        ...attrs,
        "rootClassName": hashId.value,
        "class": _class.classNames(hashId.value, attrs.class),
        "getContainer": getContainer || (getPopupContainer == null ? void 0 : getPopupContainer.value),
        "prefixCls": prefixCls.value,
        "wrapClassName": wrapClassNameExtended,
        "visible": open != null ? open : visible,
        "onClose": handleCancel,
        "focusTriggerAfterClose": focusTriggerAfterClose,
        "transitionName": transition.getTransitionName(rootPrefixCls.value, "zoom", props.transitionName),
        "maskTransitionName": transition.getTransitionName(rootPrefixCls.value, "fade", props.maskTransitionName),
        "mousePosition": (_b = restProps.mousePosition) != null ? _b : mousePosition
      }, {
        ...slots,
        footer: slots.footer || renderFooter,
        closeIcon: () => {
          return vue.createVNode("span", {
            "class": `${prefixCls.value}-close-x`
          }, [closeIcon || vue.createVNode(iconsVue.CloseOutlined, {
            "class": `${prefixCls.value}-close-icon`
          }, null)]);
        }
      }));
    };
  }
});

exports.default = AModal;
//# sourceMappingURL=Modal.cjs.map
