import { defineComponent, reactive, computed, toRefs, getCurrentInstance, onBeforeUnmount, nextTick, resolveComponent, withDirectives, openBlock, createElementBlock, normalizeClass, withModifiers, createVNode, renderSlot, createElementVNode, toDisplayString, vShow } from 'vue';
import '../../../hooks/index.mjs';
import { useOption } from './useOption.mjs';
import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';
import { useNamespace } from '../../../hooks/use-namespace/index.mjs';

const _sfc_main = defineComponent({
  name: "ElOption",
  componentName: "ElOption",
  props: {
    value: {
      required: true,
      type: [String, Number, Boolean, Object]
    },
    label: [String, Number],
    created: Boolean,
    disabled: {
      type: Boolean,
      default: false
    }
  },
  setup(props) {
    const ns = useNamespace("select");
    const states = reactive({
      index: -1,
      groupDisabled: false,
      visible: true,
      hitState: false,
      hover: false
    });
    const { currentLabel, itemSelected, isDisabled, select, hoverItem } = useOption(props, states);
    const isMultiple = computed(() => select.props.multiple);
    const { visible, hover } = toRefs(states);
    const vm = getCurrentInstance().proxy;
    select.onOptionCreate(vm);
    onBeforeUnmount(() => {
      const key = vm.value;
      const { selected } = select;
      const selectedOptions = isMultiple.value ? selected : [selected];
      const doesSelected = selectedOptions.some((item) => {
        return item.value === vm.value;
      });
      nextTick(() => {
        if (select.cachedOptions.get(key) === vm && !doesSelected) {
          select.cachedOptions.delete(key);
        }
      });
      select.onOptionDestroy(key, vm);
    });
    function selectOptionClick() {
      if (props.disabled !== true && states.groupDisabled !== true) {
        select.handleOptionSelect(vm, true);
      }
    }
    return {
      ns,
      currentLabel,
      itemSelected,
      isDisabled,
      isMultiple,
      select,
      hoverItem,
      visible,
      hover,
      selectOptionClick,
      states
    };
  }
});
const _hoisted_1 = ["title"];
const _hoisted_2 = ["title"];
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  const _component_el_checkbox = resolveComponent("el-checkbox");
  return withDirectives((openBlock(), createElementBlock("li", {
    class: normalizeClass([
      _ctx.ns.be("dropdown", "item"),
      _ctx.ns.is("disabled", _ctx.isDisabled),
      {
        selected: _ctx.itemSelected && !_ctx.isMultiple,
        hover: _ctx.hover
      }
    ]),
    onMouseenter: _cache[0] || (_cache[0] = (...args) => _ctx.hoverItem && _ctx.hoverItem(...args)),
    onClick: _cache[1] || (_cache[1] = withModifiers((...args) => _ctx.selectOptionClick && _ctx.selectOptionClick(...args), ["stop", "prevent"]))
  }, [
    _ctx.isMultiple ? (openBlock(), createElementBlock("div", {
      key: 0,
      class: normalizeClass(_ctx.ns.be("dropdown", "item-multiple"))
    }, [
      createVNode(_component_el_checkbox, {
        "model-value": _ctx.itemSelected,
        disabled: _ctx.isDisabled
      }, null, 8, ["model-value", "disabled"]),
      renderSlot(_ctx.$slots, "default", {}, () => [
        createElementVNode("span", { title: _ctx.currentLabel }, toDisplayString(_ctx.currentLabel), 9, _hoisted_1)
      ])
    ], 2)) : renderSlot(_ctx.$slots, "default", { key: 1 }, () => [
      createElementVNode("span", { title: _ctx.currentLabel }, toDisplayString(_ctx.currentLabel), 9, _hoisted_2)
    ])
  ], 34)), [
    [vShow, _ctx.visible]
  ]);
}
var Option = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "/Users/judai/code/d-element-plus/packages/components/select/src/option.vue"]]);

export { Option as default };
//# sourceMappingURL=option.mjs.map
