'use strict';

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

var vue = require('vue');
require('../../../utils/index.cjs');
require('../../../vue-components/vc-trigger/index.cjs');
require('../../../vue-components/transition/index.cjs');
var useMenuContext = require('./hooks/useMenuContext.cjs');
var placements = require('./placements.cjs');
var raf = require('../../../utils/vue/raf.cjs');
var transition = require('../../../vue-components/transition/src/transition.cjs');
var Trigger = require('../../../vue-components/vc-trigger/src/Trigger.cjs');
var _class = require('../../../utils/dom/class.cjs');

const popupPlacementMap = {
  "horizontal": "bottomLeft",
  "vertical": "rightTop",
  "vertical-left": "rightTop",
  "vertical-right": "leftTop"
};
var PopupTrigger = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "PopupTrigger",
  inheritAttrs: false,
  props: {
    prefixCls: String,
    mode: String,
    visible: Boolean,
    // popup: React.ReactNode;
    popupClassName: String,
    popupOffset: Array,
    disabled: Boolean,
    onVisibleChange: Function
  },
  slots: Object,
  emits: ["visibleChange"],
  setup(props, {
    slots,
    emit
  }) {
    const innerVisible = vue.shallowRef(false);
    const {
      getPopupContainer,
      rtl,
      subMenuOpenDelay,
      subMenuCloseDelay,
      builtinPlacements,
      triggerSubMenuAction,
      forceSubMenuRender,
      motion,
      defaultMotions,
      rootClassName
    } = useMenuContext.useInjectMenu();
    const forceRender = useMenuContext.useInjectForceRender();
    const placement = vue.computed(() => rtl.value ? {
      ...placements.placementsRtl,
      ...builtinPlacements.value
    } : {
      ...placements.placements,
      ...builtinPlacements.value
    });
    const popupPlacement = vue.computed(() => popupPlacementMap[props.mode]);
    const visibleRef = vue.shallowRef();
    vue.watch(() => props.visible, (visible) => {
      raf.raf.cancel(visibleRef.value);
      visibleRef.value = raf.raf(() => {
        innerVisible.value = visible;
      });
    }, {
      immediate: true
    });
    vue.onBeforeUnmount(() => {
      raf.raf.cancel(visibleRef.value);
    });
    const onVisibleChange = (visible) => {
      emit("visibleChange", visible);
    };
    const mergedMotion = vue.computed(() => {
      var _a, _b;
      const m = motion.value || ((_a = defaultMotions.value) == null ? void 0 : _a[props.mode]) || ((_b = defaultMotions.value) == null ? void 0 : _b.other);
      const res = typeof m === "function" ? m() : m;
      return res ? transition.getTransitionProps(res.name, {
        css: true
      }) : void 0;
    });
    return () => {
      const {
        prefixCls,
        popupClassName,
        mode,
        popupOffset,
        disabled
      } = props;
      return vue.createVNode(Trigger.default, {
        "prefixCls": prefixCls,
        "popupClassName": _class.classNames(`${prefixCls}-popup`, {
          [`${prefixCls}-rtl`]: rtl.value
        }, popupClassName, rootClassName.value),
        "stretch": mode === "horizontal" ? "minWidth" : null,
        "getPopupContainer": getPopupContainer.value,
        "builtinPlacements": placement.value,
        "popupPlacement": popupPlacement.value,
        "popupVisible": innerVisible.value,
        "popupAlign": popupOffset && {
          offset: popupOffset
        },
        "action": disabled ? [] : [triggerSubMenuAction.value],
        "mouseEnterDelay": subMenuOpenDelay.value,
        "mouseLeaveDelay": subMenuCloseDelay.value,
        "onPopupVisibleChange": onVisibleChange,
        "forceRender": forceRender || forceSubMenuRender.value,
        "popupAnimation": mergedMotion.value
      }, {
        popup: slots.popup,
        default: slots.default
      });
    };
  }
});

exports.default = PopupTrigger;
//# sourceMappingURL=PopupTrigger.cjs.map
