import { defineComponent, ref, toRef, computed, createVNode } from 'vue';
import { ExclamationCircleFilled } from '@ant-design/icons-vue';
import '../../../utils/index.mjs';
import '../../../locale/index.mjs';
import '../../../hooks/index.mjs';
import '../../../vue-components/index.mjs';
import ActionButton from '../../button/src/ActionButton.mjs';
import useConfigInject from '../../config-provider/src/hooks/useConfigInject.mjs';
import { Popover } from '../../popover/index.mjs';
import { Button } from '../../button/index.mjs';
import '../../locale-provider/index.mjs';
import '../../tooltip/index.mjs';
import usePopconfirmStyle from '../style/index.mjs';
import { popconfirmProps } from './props.mjs';
import { initDefaultProps } from '../../../utils/vue/initDefaultProps.mjs';
import { tooltipDefaultProps } from '../../tooltip/src/props.mjs';
import { devWarning } from '../../../utils/log.mjs';
import { useMergedState } from '../../../hooks/use-merged-state/index.mjs';
import { KeyCode } from '../../../utils/KeyCode.mjs';
import { useLocaleReceiver } from '../../locale-provider/src/useLocaleReceiver.mjs';
import localeValues from '../../../locale/lang/en_US.mjs';
import { convertLegacyProps } from '../../button/src/utils.mjs';
import { omit } from '../../../utils/lang/omit.mjs';
import { classNames } from '../../../utils/dom/class.mjs';
import { getTransitionName } from '../../../vue-components/transition/src/transition.mjs';
import { cloneVNodes } from '../../../utils/vue/vnode.mjs';

var APopconfirm = /* @__PURE__ */ defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "APopconfirm",
  inheritAttrs: false,
  props: initDefaultProps(popconfirmProps(), {
    ...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 = ref();
    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] = useMergedState(false, {
      value: 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.ESC && open)
        settingOpen(false, e);
    };
    const onOpenChange = (value) => {
      const {
        disabled
      } = props;
      if (disabled)
        return;
      settingOpen(value);
    };
    const {
      prefixCls: prefixClsConfirm,
      getPrefixCls
    } = useConfigInject("popconfirm", props);
    const rootPrefixCls = computed(() => getPrefixCls());
    const btnPrefixCls = computed(() => getPrefixCls("btn"));
    const [wrapSSR] = usePopconfirmStyle(prefixClsConfirm);
    const [popconfirmLocale] = useLocaleReceiver("Popconfirm", localeValues.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)) || createVNode(ExclamationCircleFilled, null, null),
        showCancel = true
      } = props;
      const {
        cancelButton,
        okButton
      } = slots;
      const cancelProps = {
        onClick: onCancel,
        size: "small",
        ...cancelButtonProps
      };
      const okProps = {
        onClick: onConfirm,
        ...convertLegacyProps(okType),
        size: "small",
        ...okButtonProps
      };
      return createVNode("div", {
        "class": `${prefixClsConfirm.value}-inner-content`
      }, [createVNode("div", {
        "class": `${prefixClsConfirm.value}-message`
      }, [icon && createVNode("span", {
        "class": `${prefixClsConfirm.value}-message-icon`
      }, [icon]), createVNode("div", {
        "class": [`${prefixClsConfirm.value}-message-title`, {
          [`${prefixClsConfirm.value}-message-title-only`]: !!description
        }]
      }, [title])]), description && createVNode("div", {
        "class": `${prefixClsConfirm.value}-description`
      }, [description]), createVNode("div", {
        "class": `${prefixClsConfirm.value}-buttons`
      }, [showCancel ? cancelButton ? cancelButton(cancelProps) : createVNode(Button, cancelProps, {
        default: () => [cancelText || popconfirmLocale.value.cancelText]
      }) : null, okButton ? okButton(okProps) : createVNode(ActionButton, {
        "buttonProps": {
          size: "small",
          ...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(restProps, ["title", "content", "cancelText", "okText", "onUpdate:open", "onConfirm", "onCancel", "prefixCls"]);
      const overlayClassNames = classNames(prefixClsConfirm.value, overlayClassName);
      return wrapSSR(createVNode(Popover, {
        ...otherProps,
        ...attrs,
        "trigger": trigger,
        "placement": placement,
        "onOpenChange": onOpenChange,
        "open": open.value,
        "overlayClassName": overlayClassNames,
        "transitionName": getTransitionName(rootPrefixCls.value, "zoom-big", props.transitionName),
        "ref": rootRef,
        "data-popover-inject": true
      }, {
        default: () => {
          var _a;
          return [cloneVNodes(((_a = slots.default) == null ? void 0 : _a.call(slots)) || [], {
            onKeydown: (e) => {
              onKeyDown(e);
            }
          }, false)];
        },
        content: renderOverlay
      }));
    };
  }
});

export { APopconfirm as default };
//# sourceMappingURL=Popconfirm.mjs.map
