'use strict';

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

var vue = require('vue');
var index = require('../../../components/menu/index.cjs');
var index$1 = require('../../../components/spin/index.cjs');
var MentionsContext = require('./MentionsContext.cjs');

function noop() {
}
var DropdownMenu = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "DropdownMenu",
  props: {
    prefixCls: String,
    options: {
      type: Array,
      default: () => []
    }
  },
  setup(props, {
    slots
  }) {
    const {
      activeIndex,
      setActiveIndex,
      selectOption,
      onFocus = noop,
      loading
    } = vue.inject(MentionsContext.default, {
      activeIndex: vue.shallowRef(),
      loading: vue.shallowRef(false)
    });
    let timeoutId;
    const onMousedown = (e) => {
      clearTimeout(timeoutId);
      timeoutId = setTimeout(() => {
        onFocus(e);
      });
    };
    vue.onBeforeUnmount(() => {
      clearTimeout(timeoutId);
    });
    return () => {
      const {
        prefixCls,
        options
      } = props;
      const activeOption = options[activeIndex.value] || {};
      return vue.createVNode(index.Menu, {
        "prefixCls": `${prefixCls}-menu`,
        "activeKey": activeOption.value,
        "onSelect": ({
          key
        }) => {
          const option = options.find(({
            value
          }) => value === key);
          selectOption(option);
        },
        "onMousedown": onMousedown
      }, {
        default: () => [!loading.value && options.map((option, index$1) => {
          const {
            value,
            disabled,
            label = option.value,
            class: className,
            style
          } = option;
          return vue.createVNode(index.Item, {
            "key": value,
            "disabled": disabled,
            "onMouseenter": () => {
              setActiveIndex(index$1);
            },
            "class": className,
            "style": style
          }, {
            default: () => {
              var _a, _b;
              return [(_b = (_a = slots.option) == null ? void 0 : _a.call(slots, option)) != null ? _b : typeof label === "function" ? label(option) : label];
            }
          });
        }), !loading.value && options.length === 0 ? vue.createVNode(index.Item, {
          "key": "notFoundContent",
          "disabled": true
        }, {
          default: () => {
            var _a;
            return [(_a = slots.notFoundContent) == null ? void 0 : _a.call(slots)];
          }
        }) : null, loading.value && vue.createVNode(index.Item, {
          "key": "loading",
          "disabled": true
        }, {
          default: () => [vue.createVNode(index$1.Spin, {
            "size": "small"
          }, null)]
        })]
      });
    };
  }
});

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