"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const index = require("../../../hooks/use-namespace/index.js");
const index$1 = require("../../../hooks/use-id/index.js");
const option = require("./option.js");
const useOption = require("./useOption.js");
const Vue = require("vue");
var option_vue_vue_type_script_lang_default = Vue.defineComponent({
  name: option.COMPONENT_NAME,
  componentName: option.COMPONENT_NAME,
  props: option.optionProps,
  setup(props) {
    const ns = index.useNamespace("select");
    const id = index$1.useId();
    const containerKls = Vue.computed(() => [
      ns.be("dropdown", "item"),
      ns.is("disabled", Vue.unref(isDisabled)),
      ns.is("selected", Vue.unref(itemSelected)),
      ns.is("hovering", Vue.unref(hover))
    ]);
    const states = Vue.reactive({
      index: -1,
      groupDisabled: false,
      visible: true,
      hover: false
    });
    const { currentLabel, itemSelected, isDisabled, select, hoverItem, updateOption } = useOption.useOption(props, states);
    const { visible, hover } = Vue.toRefs(states);
    const vm = Vue.getCurrentInstance().proxy;
    select.onOptionCreate(vm);
    Vue.onBeforeUnmount(() => {
      const key = vm.value;
      Vue.nextTick(() => {
        const { selected: selectedOptions } = select.states;
        const doesSelected = selectedOptions.some((item) => {
          return item.value === vm.value;
        });
        if (select.states.cachedOptions.get(key) === vm && !doesSelected) select.states.cachedOptions.delete(key);
      });
      select.onOptionDestroy(key, vm);
    });
    function selectOptionClick() {
      if (!isDisabled.value) select.handleOptionSelect(vm);
    }
    return {
      ns,
      id,
      containerKls,
      currentLabel,
      itemSelected,
      isDisabled,
      select,
      visible,
      hover,
      states,
      hoverItem,
      updateOption,
      selectOptionClick
    };
  }
});
exports.default = option_vue_vue_type_script_lang_default;
