'use strict';

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

var vue = require('vue');
require('../../../utils/index.cjs');
var Trigger = require('../../vc-trigger/src/Trigger.cjs');
var placements = require('./placements.cjs');
var vueTypes = require('../../../utils/vue/vueTypes.cjs');
var props = require('../../../utils/vue/props.cjs');
var vnode = require('../../../utils/vue/vnode.cjs');
var _class = require('../../../utils/dom/class.cjs');

var VcDropdown = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  props: {
    minOverlayWidthMatchTrigger: {
      type: Boolean,
      default: void 0
    },
    arrow: {
      type: Boolean,
      default: false
    },
    prefixCls: vueTypes.default.string.def("rc-dropdown"),
    transitionName: String,
    overlayClassName: vueTypes.default.string.def(""),
    openClassName: String,
    animation: vueTypes.default.any,
    align: vueTypes.default.object,
    overlayStyle: {
      type: Object,
      default: void 0
    },
    placement: vueTypes.default.string.def("bottomLeft"),
    overlay: vueTypes.default.any,
    trigger: vueTypes.default.oneOfType([vueTypes.default.string, vueTypes.default.arrayOf(vueTypes.default.string)]).def("hover"),
    alignPoint: {
      type: Boolean,
      default: void 0
    },
    showAction: vueTypes.default.array,
    hideAction: vueTypes.default.array,
    getPopupContainer: Function,
    visible: {
      type: Boolean,
      default: void 0
    },
    defaultVisible: {
      type: Boolean,
      default: false
    },
    mouseEnterDelay: vueTypes.default.number.def(0.15),
    mouseLeaveDelay: vueTypes.default.number.def(0.1)
  },
  emits: ["visibleChange", "overlayClick"],
  setup(props$1, {
    slots,
    emit,
    expose
  }) {
    const triggerVisible = vue.ref(!!props$1.visible);
    vue.watch(() => props$1.visible, (val) => {
      if (val !== void 0)
        triggerVisible.value = val;
    });
    const triggerRef = vue.ref();
    expose({
      triggerRef
    });
    const onClick = (e) => {
      if (props$1.visible === void 0)
        triggerVisible.value = false;
      emit("overlayClick", e);
    };
    const onVisibleChange = (visible) => {
      if (props$1.visible === void 0)
        triggerVisible.value = visible;
      emit("visibleChange", visible);
    };
    const getMenuElement = () => {
      var _a;
      const overlayElement = (_a = slots.overlay) == null ? void 0 : _a.call(slots);
      const extraOverlayProps = {
        prefixCls: `${props$1.prefixCls}-menu`,
        onClick
      };
      return vue.createVNode(vue.Fragment, {
        "key": props.skipFlattenKey
      }, [props$1.arrow && vue.createVNode("div", {
        "class": `${props$1.prefixCls}-arrow`
      }, null), vnode.cloneElement(overlayElement, extraOverlayProps, false)]);
    };
    const minOverlayWidthMatchTrigger = vue.computed(() => {
      const {
        minOverlayWidthMatchTrigger: matchTrigger = !props$1.alignPoint
      } = props$1;
      return matchTrigger;
    });
    const renderChildren = () => {
      var _a;
      const children = (_a = slots.default) == null ? void 0 : _a.call(slots);
      return triggerVisible.value && children ? vnode.cloneElement(children[0], {
        class: props$1.openClassName || `${props$1.prefixCls}-open`
      }, false) : children;
    };
    const triggerHideAction = vue.computed(() => {
      if (!props$1.hideAction && props$1.trigger.includes("contextmenu"))
        return ["click"];
      return props$1.hideAction;
    });
    return () => {
      const {
        prefixCls,
        arrow,
        showAction,
        overlayStyle,
        trigger,
        placement,
        align,
        getPopupContainer,
        transitionName,
        animation,
        overlayClassName,
        ...otherProps
      } = props$1;
      return vue.createVNode(Trigger.default, {
        ...otherProps,
        "prefixCls": prefixCls,
        "ref": triggerRef,
        "popupClassName": _class.classNames(overlayClassName, {
          [`${prefixCls}-show-arrow`]: arrow
        }),
        "popupStyle": overlayStyle,
        "builtinPlacements": placements.default,
        "action": trigger,
        "showAction": showAction,
        "hideAction": triggerHideAction.value || [],
        "popupPlacement": placement,
        "popupAlign": align,
        "popupTransitionName": transitionName,
        "popupAnimation": animation,
        "popupVisible": triggerVisible.value,
        "stretch": minOverlayWidthMatchTrigger.value ? "minWidth" : "",
        "onPopupVisibleChange": onVisibleChange,
        "getPopupContainer": getPopupContainer
      }, {
        popup: getMenuElement,
        default: renderChildren
      });
    };
  }
});

exports.default = VcDropdown;
//# sourceMappingURL=Dropdown.cjs.map
