'use strict';

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

var vue = require('vue');
var CloseOutlined = require('@ant-design/icons-vue');
var classNames = require('../_util/classNames.js');
require('../vc-dialog/index.js');
var index = require('../_util/vue-types/index.js');
var addEventListener = require('../vc-util/Dom/addEventListener.js');
require('../button/index.js');
var buttonTypes = require('../button/buttonTypes.js');
var LocaleReceiver = require('../locale-provider/LocaleReceiver.js');
var initDefaultProps = require('../_util/props-util/initDefaultProps.js');
var type = require('../_util/type.js');
var styleChecker = require('../_util/styleChecker.js');
require('../hooks/index.js');
var transition = require('../_util/components/transition.js');
var warning = require('../_util/warning.js');
var index$1 = require('./style/index.js');
var useConfigInject = require('../config-provider/hooks/useConfigInject.js');
var button = require('../button/button.js');
var DialogWrap = require('../vc-dialog/DialogWrap.js');

let mousePosition;
const getClickPosition = (e) => {
  mousePosition = {
    x: e.pageX,
    y: e.pageY
  };
  setTimeout(() => mousePosition = null, 100);
};
if (styleChecker.canUseDocElement())
  addEventListener.default(document.documentElement, "click", getClickPosition, true);
const modalProps = () => ({
  "prefixCls": String,
  /** @deprecated Please use `open` instead. */
  "visible": {
    type: Boolean,
    default: void 0
  },
  "open": {
    type: Boolean,
    default: void 0
  },
  "confirmLoading": {
    type: Boolean,
    default: void 0
  },
  "title": index.default.any,
  "closable": {
    type: Boolean,
    default: void 0
  },
  "closeIcon": index.default.any,
  "onOk": Function,
  "onCancel": Function,
  "onUpdate:visible": Function,
  "onChange": Function,
  "afterClose": Function,
  "centered": {
    type: Boolean,
    default: void 0
  },
  "width": [String, Number],
  "footer": index.default.any,
  "okText": index.default.any,
  "okType": String,
  "cancelText": index.default.any,
  "icon": index.default.any,
  "maskClosable": {
    type: Boolean,
    default: void 0
  },
  "forceRender": {
    type: Boolean,
    default: void 0
  },
  "okButtonProps": type.objectType(),
  "cancelButtonProps": type.objectType(),
  "destroyOnClose": {
    type: Boolean,
    default: void 0
  },
  "wrapClassName": String,
  "maskTransitionName": String,
  "transitionName": String,
  "getContainer": {
    type: [String, Function, Boolean, Object],
    default: void 0
  },
  "zIndex": Number,
  "bodyStyle": type.objectType(),
  "maskStyle": type.objectType(),
  "mask": {
    type: Boolean,
    default: void 0
  },
  "keyboard": {
    type: Boolean,
    default: void 0
  },
  "wrapProps": Object,
  "focusTriggerAfterClose": {
    type: Boolean,
    default: void 0
  },
  "modalRender": Function,
  "mousePosition": type.objectType()
});
var Modal = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "AModal",
  inheritAttrs: false,
  props: initDefaultProps.default(modalProps(), {
    width: 520,
    confirmLoading: false,
    okType: "primary"
  }),
  setup(props, {
    emit,
    slots,
    attrs
  }) {
    const [locale] = LocaleReceiver.useLocaleReceiver("Modal");
    const {
      prefixCls,
      rootPrefixCls,
      direction,
      getPopupContainer
    } = useConfigInject.default("modal", props);
    const [wrapSSR, hashId] = index$1.default(prefixCls);
    warning.default(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(button.default, vue.mergeProps({
        "onClick": handleCancel
      }, props.cancelButtonProps), {
        default: () => [cancelText || locale.value.cancelText]
      }), vue.createVNode(button.default, vue.mergeProps(buttonTypes.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 = classNames.default(wrapClassName, {
        [`${prefixCls.value}-centered`]: !!centered,
        [`${prefixCls.value}-wrap-rtl`]: direction.value === "rtl"
      });
      return wrapSSR(vue.createVNode(DialogWrap.default, vue.mergeProps(restProps, attrs, {
        "rootClassName": hashId.value,
        "class": classNames.default(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(CloseOutlined.CloseOutlined, {
            "class": `${prefixCls.value}-close-icon`
          }, null)]);
        }
      }));
    };
  }
});

exports.default = Modal;
exports.modalProps = modalProps;
//# sourceMappingURL=Modal.js.map
