"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const style = require("../../../utils/dom/style.js");
const index$7 = require("../../../hooks/use-locale/index.js");
const index$6 = require("../../../hooks/use-namespace/index.js");
const index$8 = require("../../../hooks/use-id/index.js");
const index$1 = require("../../icon/index.js");
const onlyChild = require("../../slot/src/only-child.js");
const useFormCommonProps = require("../../form/src/hooks/use-form-common-props.js");
const index$3 = require("../../tooltip/index.js");
const index$4 = require("../../scrollbar/index.js");
const index$5 = require("../../button/index.js");
const index$2 = require("../../roving-focus-group/index.js");
const dropdown = require("./dropdown.js");
const tokens = require("./tokens.js");
const index = require("../../../../../@element-plus/icons-vue/dist/index.js");
const vue = require("vue");
const castArray = require("../../../../../lodash-es/castArray.js");
const { ButtonGroup: ElButtonGroup } = index$5.ElButton;
var dropdown_vue_vue_type_script_lang_default = vue.defineComponent({
  name: "ElDropdown",
  components: {
    ElButton: index$5.ElButton,
    ElButtonGroup,
    ElScrollbar: index$4.ElScrollbar,
    ElTooltip: index$3.ElTooltip,
    ElRovingFocusGroup: index$2.default,
    ElOnlyChild: onlyChild.OnlyChild,
    ElIcon: index$1.ElIcon,
    ArrowDown: index.ArrowDown
  },
  props: dropdown.dropdownProps,
  emits: [
    "visible-change",
    "click",
    "command"
  ],
  setup(props, { emit }) {
    const _instance = vue.getCurrentInstance();
    const ns = index$6.useNamespace("dropdown");
    const { t } = index$7.useLocale();
    const triggeringElementRef = vue.ref();
    const referenceElementRef = vue.ref();
    const popperRef = vue.ref();
    const contentRef = vue.ref();
    const scrollbar = vue.ref(null);
    const currentTabId = vue.ref(null);
    const isUsingKeyboard = vue.ref(false);
    const wrapStyle = vue.computed(() => ({ maxHeight: style.addUnit(props.maxHeight) }));
    const dropdownTriggerKls = vue.computed(() => [ns.m(dropdownSize.value)]);
    const trigger = vue.computed(() => castArray.default(props.trigger));
    const defaultTriggerId = index$8.useId().value;
    const triggerId = vue.computed(() => props.id || defaultTriggerId);
    function handleClick() {
      var _a;
      (_a = popperRef.value) == null ? void 0 : _a.onClose(void 0, 0);
    }
    function handleClose() {
      var _a;
      (_a = popperRef.value) == null ? void 0 : _a.onClose();
    }
    function handleOpen() {
      var _a;
      (_a = popperRef.value) == null ? void 0 : _a.onOpen();
    }
    const dropdownSize = useFormCommonProps.useFormSize();
    function commandHandler(...args) {
      emit("command", ...args);
    }
    function onItemEnter() {
    }
    function onItemLeave() {
      const contentEl = vue.unref(contentRef);
      trigger.value.includes("hover") && (contentEl == null ? void 0 : contentEl.focus({ preventScroll: true }));
      currentTabId.value = null;
    }
    function handleCurrentTabIdChange(id) {
      currentTabId.value = id;
    }
    function handleBeforeShowTooltip() {
      emit("visible-change", true);
    }
    function handleShowTooltip(event) {
      var _a;
      isUsingKeyboard.value = (event == null ? void 0 : event.type) === "keydown";
      (_a = contentRef.value) == null ? void 0 : _a.focus();
    }
    function handleBeforeHideTooltip() {
      emit("visible-change", false);
    }
    vue.provide(tokens.DROPDOWN_INJECTION_KEY, {
      contentRef,
      role: vue.computed(() => props.role),
      triggerId,
      isUsingKeyboard,
      onItemEnter,
      onItemLeave,
      handleClose
    });
    vue.provide(tokens.DROPDOWN_INSTANCE_INJECTION_KEY, {
      instance: _instance,
      dropdownSize,
      handleClick,
      commandHandler,
      trigger: vue.toRef(props, "trigger"),
      hideOnClick: vue.toRef(props, "hideOnClick")
    });
    const handlerMainButtonClick = (event) => {
      emit("click", event);
    };
    return {
      t,
      ns,
      scrollbar,
      wrapStyle,
      dropdownTriggerKls,
      dropdownSize,
      triggerId,
      currentTabId,
      handleCurrentTabIdChange,
      handlerMainButtonClick,
      handleClose,
      handleOpen,
      handleBeforeShowTooltip,
      handleShowTooltip,
      handleBeforeHideTooltip,
      popperRef,
      contentRef,
      triggeringElementRef,
      referenceElementRef
    };
  }
});
exports.default = dropdown_vue_vue_type_script_lang_default;
