"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const aria = require("../../../constants/aria.js");
const event = require("../../../utils/dom/event.js");
const index = require("../../../hooks/use-id/index.js");
const rovingFocusGroup = require("./roving-focus-group.js");
const tokens = require("./tokens.js");
const Vue = require("vue");
var roving_focus_item_vue_vue_type_script_lang_default = Vue.defineComponent({
  components: { ElRovingFocusCollectionItem: rovingFocusGroup.ElCollectionItem },
  props: {
    focusable: {
      type: Boolean,
      default: true
    },
    active: Boolean
  },
  emits: [
    "mousedown",
    "focus",
    "keydown"
  ],
  setup(props, { emit }) {
    const { currentTabbedId, onItemFocus, onItemShiftTab, onKeydown } = Vue.inject(tokens.ROVING_FOCUS_GROUP_INJECTION_KEY, void 0);
    const id = index.useId();
    const rovingFocusGroupItemRef = Vue.ref();
    const handleMousedown = event.composeEventHandlers((e) => {
      emit("mousedown", e);
    }, (e) => {
      if (!props.focusable) e.preventDefault();
      else onItemFocus(Vue.unref(id));
    });
    const handleFocus = event.composeEventHandlers((e) => {
      emit("focus", e);
    }, () => {
      onItemFocus(Vue.unref(id));
    });
    const handleKeydown = event.composeEventHandlers((e) => {
      emit("keydown", e);
    }, (e) => {
      const { shiftKey, target, currentTarget } = e;
      if (event.getEventCode(e) === aria.EVENT_CODE.tab && shiftKey) {
        onItemShiftTab();
        return;
      }
      if (target !== currentTarget) return;
      onKeydown(e);
    });
    const isCurrentTab = Vue.computed(() => currentTabbedId.value === Vue.unref(id));
    Vue.provide(tokens.ROVING_FOCUS_GROUP_ITEM_INJECTION_KEY, {
      rovingFocusGroupItemRef,
      tabIndex: Vue.computed(() => Vue.unref(isCurrentTab) ? 0 : -1),
      handleMousedown,
      handleFocus,
      handleKeydown
    });
    return {
      id,
      handleKeydown,
      handleFocus,
      handleMousedown
    };
  }
});
exports.default = roving_focus_item_vue_vue_type_script_lang_default;
