'use strict';

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

var vue = require('vue');
var iconsVue = require('@ant-design/icons-vue');
require('../../../utils/index.cjs');
require('../../../locale/index.cjs');
require('../../../hooks/index.cjs');
require('../../../vue-components/index.cjs');
var ActionButton = require('../../button/src/ActionButton.cjs');
var useConfigInject = require('../../config-provider/src/hooks/useConfigInject.cjs');
var index$3 = require('../../popover/index.cjs');
var index$2 = require('../../button/index.cjs');
require('../../locale-provider/index.cjs');
require('../../tooltip/index.cjs');
var index$1 = require('../style/index.cjs');
var props = require('./props.cjs');
var initDefaultProps = require('../../../utils/vue/initDefaultProps.cjs');
var props$1 = require('../../tooltip/src/props.cjs');
var log = require('../../../utils/log.cjs');
var index = require('../../../hooks/use-merged-state/index.cjs');
var KeyCode = require('../../../utils/KeyCode.cjs');
var useLocaleReceiver = require('../../locale-provider/src/useLocaleReceiver.cjs');
var en_US = require('../../../locale/lang/en_US.cjs');
var utils = require('../../button/src/utils.cjs');
var omit = require('../../../utils/lang/omit.cjs');
var _class = require('../../../utils/dom/class.cjs');
var transition = require('../../../vue-components/transition/src/transition.cjs');
var vnode = require('../../../utils/vue/vnode.cjs');

var APopconfirm = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "APopconfirm",
  inheritAttrs: false,
  props: initDefaultProps.initDefaultProps(props.popconfirmProps(), {
    ...props$1.tooltipDefaultProps(),
    trigger: "click",
    placement: "top",
    mouseEnterDelay: 0.1,
    mouseLeaveDelay: 0.1,
    arrowPointAtCenter: false,
    autoAdjustOverflow: true,
    okType: "primary",
    disabled: false
  }),
  slots: Object,
  // emits: ['update:open', 'visibleChange'],
  setup(props, {
    slots,
    emit,
    expose,
    attrs
  }) {
    const rootRef = vue.ref();
    log.devWarning(props.visible === void 0, "Popconfirm", "`visible` will be removed in next major version, please use `open` instead.");
    expose({
      getPopupDomNode: () => {
        var _a, _b;
        return (_b = (_a = rootRef.value) == null ? void 0 : _a.getPopupDomNode) == null ? void 0 : _b.call(_a);
      }
    });
    const [open, setOpen] = index.useMergedState(false, {
      value: vue.toRef(props, "open")
    });
    const settingOpen = (value, e) => {
      if (props.open === void 0)
        setOpen(value);
      emit("update:open", value);
      emit("openChange", value, e);
    };
    const close = (e) => {
      settingOpen(false, e);
    };
    const onConfirm = (e) => {
      var _a;
      return (_a = props.onConfirm) == null ? void 0 : _a.call(props, e);
    };
    const onCancel = (e) => {
      var _a;
      settingOpen(false, e);
      (_a = props.onCancel) == null ? void 0 : _a.call(props, e);
    };
    const onKeyDown = (e) => {
      if (e.keyCode === KeyCode.KeyCode.ESC && open)
        settingOpen(false, e);
    };
    const onOpenChange = (value) => {
      const {
        disabled
      } = props;
      if (disabled)
        return;
      settingOpen(value);
    };
    const {
      prefixCls: prefixClsConfirm,
      getPrefixCls
    } = useConfigInject.default("popconfirm", props);
    const rootPrefixCls = vue.computed(() => getPrefixCls());
    const btnPrefixCls = vue.computed(() => getPrefixCls("btn"));
    const [wrapSSR] = index$1.default(prefixClsConfirm);
    const [popconfirmLocale] = useLocaleReceiver.useLocaleReceiver("Popconfirm", en_US.default.Popconfirm);
    const renderOverlay = () => {
      var _a, _b, _c, _d, _e;
      const {
        okButtonProps,
        cancelButtonProps,
        title = (_a = slots.title) == null ? void 0 : _a.call(slots),
        description = (_b = slots.description) == null ? void 0 : _b.call(slots),
        cancelText = (_c = slots.cancel) == null ? void 0 : _c.call(slots),
        okText = (_d = slots.okText) == null ? void 0 : _d.call(slots),
        okType,
        icon = ((_e = slots.icon) == null ? void 0 : _e.call(slots)) || vue.createVNode(iconsVue.ExclamationCircleFilled, null, null),
        showCancel = true
      } = props;
      const {
        cancelButton,
        okButton
      } = slots;
      const cancelProps = {
        onClick: onCancel,
        size: "small",
        ...cancelButtonProps
      };
      const okProps = {
        onClick: onConfirm,
        ...utils.convertLegacyProps(okType),
        size: "small",
        ...okButtonProps
      };
      return vue.createVNode("div", {
        "class": `${prefixClsConfirm.value}-inner-content`
      }, [vue.createVNode("div", {
        "class": `${prefixClsConfirm.value}-message`
      }, [icon && vue.createVNode("span", {
        "class": `${prefixClsConfirm.value}-message-icon`
      }, [icon]), vue.createVNode("div", {
        "class": [`${prefixClsConfirm.value}-message-title`, {
          [`${prefixClsConfirm.value}-message-title-only`]: !!description
        }]
      }, [title])]), description && vue.createVNode("div", {
        "class": `${prefixClsConfirm.value}-description`
      }, [description]), vue.createVNode("div", {
        "class": `${prefixClsConfirm.value}-buttons`
      }, [showCancel ? cancelButton ? cancelButton(cancelProps) : vue.createVNode(index$2.Button, cancelProps, {
        default: () => [cancelText || popconfirmLocale.value.cancelText]
      }) : null, okButton ? okButton(okProps) : vue.createVNode(ActionButton.default, {
        "buttonProps": {
          size: "small",
          ...utils.convertLegacyProps(okType),
          ...okButtonProps
        },
        "actionFn": onConfirm,
        "close": close,
        "prefixCls": btnPrefixCls.value,
        "quitOnNullishReturnValue": true,
        "emitEvent": true
      }, {
        default: () => [okText || popconfirmLocale.value.okText]
      })])]);
    };
    return () => {
      const {
        placement,
        overlayClassName,
        trigger = "click",
        ...restProps
      } = props;
      const otherProps = omit.omit(restProps, ["title", "content", "cancelText", "okText", "onUpdate:open", "onConfirm", "onCancel", "prefixCls"]);
      const overlayClassNames = _class.classNames(prefixClsConfirm.value, overlayClassName);
      return wrapSSR(vue.createVNode(index$3.Popover, {
        ...otherProps,
        ...attrs,
        "trigger": trigger,
        "placement": placement,
        "onOpenChange": onOpenChange,
        "open": open.value,
        "overlayClassName": overlayClassNames,
        "transitionName": transition.getTransitionName(rootPrefixCls.value, "zoom-big", props.transitionName),
        "ref": rootRef,
        "data-popover-inject": true
      }, {
        default: () => {
          var _a;
          return [vnode.cloneVNodes(((_a = slots.default) == null ? void 0 : _a.call(slots)) || [], {
            onKeydown: (e) => {
              onKeyDown(e);
            }
          }, false)];
        },
        content: renderOverlay
      }));
    };
  }
});

exports.default = APopconfirm;
//# sourceMappingURL=Popconfirm.cjs.map
