'use strict';

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

var vue = require('vue');
require('../../../hooks/index.js');
var useOption = require('./useOption.js');
var pluginVue_exportHelper = require('../../../../_virtual/plugin-vue_export-helper.js');
var index = require('../../../hooks/use-namespace/index.js');

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

exports["default"] = Option;
//# sourceMappingURL=option.js.map
