'use strict';

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

var vue = require('vue');
var CloseOutlined = require('@ant-design/icons-vue');
var en_US = require('../locale/lang/en_US.js');
var index$1 = require('../popover/index.js');
require('../_util/props-util/index.js');
var buttonTypes = require('../button/buttonTypes.js');
require('../button/index.js');
var LocaleReceiver = require('../locale-provider/LocaleReceiver.js');
require('../hooks/index.js');
var KeyCode = require('../_util/KeyCode.js');
var classNames = require('../_util/classNames.js');
var transition = require('../_util/components/transition.js');
var vnode = require('../_util/vnode.js');
var omit = require('../_util/omit.js');
var Tooltip = require('../tooltip/Tooltip.js');
var ActionButton = require('../_util/components/ActionButton.js');
var warning = require('../_util/warning.js');
var index = require('./style/index.js');
var props = require('./props.js');
var initDefaultProps = require('../_util/props-util/initDefaultProps.js');
var useMergedState = require('../hooks/useMergedState.js');
var useConfigInject = require('../config-provider/hooks/useConfigInject.js');
var button = require('../button/button.js');

var Popconfirm = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "APopconfirm",
  inheritAttrs: false,
  props: initDefaultProps.default(props.popconfirmProps(), {
    ...Tooltip.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();
    warning.default(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] = useMergedState.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.default.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.default(prefixClsConfirm);
    const [popconfirmLocale] = LocaleReceiver.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(CloseOutlined.ExclamationCircleFilled, null, null),
        showCancel = true
      } = props;
      const {
        cancelButton,
        okButton
      } = slots;
      const cancelProps = {
        onClick: onCancel,
        size: "small",
        ...cancelButtonProps
      };
      const okProps = {
        onClick: onConfirm,
        ...buttonTypes.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(button.default, cancelProps, {
        default: () => [cancelText || popconfirmLocale.value.cancelText]
      }) : null, okButton ? okButton(okProps) : vue.createVNode(ActionButton.default, {
        "buttonProps": {
          size: "small",
          ...buttonTypes.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.default(restProps, ["title", "content", "cancelText", "okText", "onUpdate:open", "onConfirm", "onCancel", "prefixCls"]);
      const overlayClassNames = classNames.default(prefixClsConfirm.value, overlayClassName);
      return wrapSSR(vue.createVNode(index$1.default, vue.mergeProps(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 = Popconfirm;
//# sourceMappingURL=popconfirm.js.map
