import { defineComponent, createVNode, Fragment } from 'vue';
import { CloseOutlined } from '@ant-design/icons-vue';
import '../../../utils/index.mjs';
import '../../../vue-components/index.mjs';
import { Button } from '../../button/index.mjs';
import '../../locale-provider/index.mjs';
import useConfigInject from '../../config-provider/src/hooks/useConfigInject.mjs';
import useStyle from '../style/index.mjs';
import { modalProps } from './props.mjs';
import { canUseDocElement } from '../../../utils/dom/styleChecker.mjs';
import { addEventListenerWrap } from '../../../utils/event/addEventListener.mjs';
import { initDefaultProps } from '../../../utils/vue/initDefaultProps.mjs';
import { useLocaleReceiver } from '../../locale-provider/src/useLocaleReceiver.mjs';
import { devWarning } from '../../../utils/log.mjs';
import { convertLegacyProps } from '../../button/src/utils.mjs';
import { classNames } from '../../../utils/dom/class.mjs';
import DialogWrap from '../../../vue-components/vc-dialog/src/DialogWrap.mjs';
import { getTransitionName } from '../../../vue-components/transition/src/transition.mjs';

let mousePosition;
function getClickPosition(e) {
  mousePosition = {
    x: e.pageX,
    y: e.pageY
  };
  setTimeout(() => mousePosition = null, 100);
}
if (canUseDocElement())
  addEventListenerWrap(document.documentElement, "click", getClickPosition, true);
var AModal = /* @__PURE__ */ defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "AModal",
  test: 1,
  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);
    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 createVNode(Fragment, null, [createVNode(Button, {
        "onClick": handleCancel,
        ...props.cancelButtonProps
      }, {
        default: () => [cancelText || locale.value.cancelText]
      }), createVNode(Button, {
        ...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, {
        ...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 { AModal as default };
//# sourceMappingURL=Modal.mjs.map
