import { defineComponent, createVNode, Fragment, mergeProps } from 'vue';
import { CloseOutlined } from '@ant-design/icons-vue';
import classNames from '../_util/classNames.mjs';
import '../vc-dialog/index.mjs';
import PropTypes from '../_util/vue-types/index.mjs';
import addEventListenerWrap from '../vc-util/Dom/addEventListener.mjs';
import '../button/index.mjs';
import { convertLegacyProps } from '../button/buttonTypes.mjs';
import { useLocaleReceiver } from '../locale-provider/LocaleReceiver.mjs';
import initDefaultProps from '../_util/props-util/initDefaultProps.mjs';
import { objectType } from '../_util/type.mjs';
import { canUseDocElement } from '../_util/styleChecker.mjs';
import '../hooks/index.mjs';
import { getTransitionName } from '../_util/components/transition.mjs';
import warning from '../_util/warning.mjs';
import useStyle from './style/index.mjs';
import useConfigInject from '../config-provider/hooks/useConfigInject.mjs';
import Button from '../button/button.mjs';
import DialogWrap from '../vc-dialog/DialogWrap.mjs';

let mousePosition;
const getClickPosition = (e) => {
  mousePosition = {
    x: e.pageX,
    y: e.pageY
  };
  setTimeout(() => mousePosition = null, 100);
};
if (canUseDocElement())
  addEventListenerWrap(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": PropTypes.any,
  "closable": {
    type: Boolean,
    default: void 0
  },
  "closeIcon": PropTypes.any,
  "onOk": Function,
  "onCancel": Function,
  "onUpdate:visible": Function,
  "onChange": Function,
  "afterClose": Function,
  "centered": {
    type: Boolean,
    default: void 0
  },
  "width": [String, Number],
  "footer": PropTypes.any,
  "okText": PropTypes.any,
  "okType": String,
  "cancelText": PropTypes.any,
  "icon": PropTypes.any,
  "maskClosable": {
    type: Boolean,
    default: void 0
  },
  "forceRender": {
    type: Boolean,
    default: void 0
  },
  "okButtonProps": objectType(),
  "cancelButtonProps": 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": objectType(),
  "maskStyle": objectType(),
  "mask": {
    type: Boolean,
    default: void 0
  },
  "keyboard": {
    type: Boolean,
    default: void 0
  },
  "wrapProps": Object,
  "focusTriggerAfterClose": {
    type: Boolean,
    default: void 0
  },
  "modalRender": Function,
  "mousePosition": objectType()
});
var Modal = /* @__PURE__ */ defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "AModal",
  inheritAttrs: false,
  props: initDefaultProps(modalProps(), {
    width: 520,
    confirmLoading: false,
    okType: "primary"
  }),
  setup(props, {
    emit,
    slots,
    attrs
  }) {
    const [locale] = useLocaleReceiver("Modal");
    const {
      prefixCls,
      rootPrefixCls,
      direction,
      getPopupContainer
    } = useConfigInject("modal", props);
    const [wrapSSR, hashId] = useStyle(prefixCls);
    warning(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 createVNode(Fragment, null, [createVNode(Button, mergeProps({
        "onClick": handleCancel
      }, props.cancelButtonProps), {
        default: () => [cancelText || locale.value.cancelText]
      }), createVNode(Button, mergeProps(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(wrapClassName, {
        [`${prefixCls.value}-centered`]: !!centered,
        [`${prefixCls.value}-wrap-rtl`]: direction.value === "rtl"
      });
      return wrapSSR(createVNode(DialogWrap, mergeProps(restProps, attrs, {
        "rootClassName": hashId.value,
        "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": getTransitionName(rootPrefixCls.value, "zoom", props.transitionName),
        "maskTransitionName": getTransitionName(rootPrefixCls.value, "fade", props.maskTransitionName),
        "mousePosition": (_b = restProps.mousePosition) != null ? _b : mousePosition
      }), {
        ...slots,
        footer: slots.footer || renderFooter,
        closeIcon: () => {
          return createVNode("span", {
            "class": `${prefixCls.value}-close-x`
          }, [closeIcon || createVNode(CloseOutlined, {
            "class": `${prefixCls.value}-close-icon`
          }, null)]);
        }
      }));
    };
  }
});

export { Modal as default, modalProps };
//# sourceMappingURL=Modal.mjs.map
