'use strict';

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

var vue = require('vue');
require('../vc-trigger/index.js');
var index = require('../_util/vue-types/index.js');
var vnode = require('../_util/vnode.js');
var classNames = require('../_util/classNames.js');
var index$1 = require('../_util/props-util/index.js');
var placements = require('./placements.js');
var Trigger = require('../vc-trigger/Trigger.js');

var Dropdown = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  props: {
    minOverlayWidthMatchTrigger: {
      type: Boolean,
      default: void 0
    },
    arrow: {
      type: Boolean,
      default: false
    },
    prefixCls: index.default.string.def("rc-dropdown"),
    transitionName: String,
    overlayClassName: index.default.string.def(""),
    openClassName: String,
    animation: index.default.any,
    align: index.default.object,
    overlayStyle: {
      type: Object,
      default: void 0
    },
    placement: index.default.string.def("bottomLeft"),
    overlay: index.default.any,
    trigger: index.default.oneOfType([index.default.string, index.default.arrayOf(index.default.string)]).def("hover"),
    alignPoint: {
      type: Boolean,
      default: void 0
    },
    showAction: index.default.array,
    hideAction: index.default.array,
    getPopupContainer: Function,
    visible: {
      type: Boolean,
      default: void 0
    },
    defaultVisible: {
      type: Boolean,
      default: false
    },
    mouseEnterDelay: index.default.number.def(0.15),
    mouseLeaveDelay: index.default.number.def(0.1)
  },
  emits: ["visibleChange", "overlayClick"],
  setup(props, {
    slots,
    emit,
    expose
  }) {
    const triggerVisible = vue.ref(!!props.visible);
    vue.watch(() => props.visible, (val) => {
      if (val !== void 0)
        triggerVisible.value = val;
    });
    const triggerRef = vue.ref();
    expose({
      triggerRef
    });
    const onClick = (e) => {
      if (props.visible === void 0)
        triggerVisible.value = false;
      emit("overlayClick", e);
    };
    const onVisibleChange = (visible) => {
      if (props.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.prefixCls}-menu`,
        onClick
      };
      return vue.createVNode(vue.Fragment, {
        "key": index$1.skipFlattenKey
      }, [props.arrow && vue.createVNode("div", {
        "class": `${props.prefixCls}-arrow`
      }, null), vnode.cloneElement(overlayElement, extraOverlayProps, false)]);
    };
    const minOverlayWidthMatchTrigger = vue.computed(() => {
      const {
        minOverlayWidthMatchTrigger: matchTrigger = !props.alignPoint
      } = props;
      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.openClassName || `${props.prefixCls}-open`
      }, false) : children;
    };
    const triggerHideAction = vue.computed(() => {
      if (!props.hideAction && props.trigger.includes("contextmenu"))
        return ["click"];
      return props.hideAction;
    });
    return () => {
      const {
        prefixCls,
        arrow,
        showAction,
        overlayStyle,
        trigger,
        placement,
        align,
        getPopupContainer,
        transitionName,
        animation,
        overlayClassName,
        ...otherProps
      } = props;
      return vue.createVNode(Trigger.default, vue.mergeProps(otherProps, {
        "prefixCls": prefixCls,
        "ref": triggerRef,
        "popupClassName": classNames.default(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 = Dropdown;
//# sourceMappingURL=Dropdown.js.map
