import { w as withInstall } from "../badge/index2.js";
import { defineComponent, inject, ref, computed, withDirectives, openBlock, createElementBlock, normalizeClass, unref, createBlock, isRef, createCommentVNode, renderSlot, createTextVNode, toDisplayString, vShow } from "vue";
import { a as _sfc_main$1 } from "../checkbox/index2.js";
const __default__ = {
  name: "LaySelectOption"
};
const _sfc_main = defineComponent({
  ...__default__,
  props: {
    label: { default: "" },
    value: null,
    disabled: { type: Boolean, default: false },
    keyword: { default: "" }
  },
  setup(__props) {
    const props = __props;
    const searchValue = inject("searchValue");
    const selectRef = inject("selectRef");
    const searchMethod = inject("searchMethod");
    const selectedValue = inject("selectedValue");
    const multiple = inject("multiple");
    const checkboxRef = ref();
    const handleSelect = () => {
      var _a;
      if (multiple.value) {
        if (!props.disabled) {
          (_a = checkboxRef.value) == null ? void 0 : _a.toggle();
        }
      } else {
        if (!props.disabled) {
          selectRef.value.hide();
          selectedValue.value = props.value;
        }
      }
    };
    const selected = computed(() => {
      if (multiple.value) {
        return selectedValue.value.indexOf(props.value) != -1;
      } else {
        return selectedValue.value === props.value;
      }
    });
    const first = ref(true);
    const display = computed(() => {
      var _a, _b;
      if (searchMethod && !first.value) {
        return searchMethod(searchValue.value, props);
      }
      first.value = false;
      return ((_a = props.keyword) == null ? void 0 : _a.toString().indexOf(searchValue.value)) > -1 || ((_b = props.label) == null ? void 0 : _b.toString().indexOf(searchValue.value)) > -1;
    });
    const classes = computed(() => {
      return [
        "layui-select-option",
        {
          "layui-this": selected.value,
          "layui-disabled": props.disabled
        }
      ];
    });
    return (_ctx, _cache) => {
      return withDirectives((openBlock(), createElementBlock("dd", {
        class: normalizeClass(unref(classes)),
        onClick: handleSelect
      }, [
        unref(multiple) ? (openBlock(), createBlock(_sfc_main$1, {
          key: 0,
          skin: "primary",
          ref_key: "checkboxRef",
          ref: checkboxRef,
          modelValue: unref(selectedValue),
          "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => isRef(selectedValue) ? selectedValue.value = $event : null),
          disabled: __props.disabled,
          value: __props.value
        }, null, 8, ["modelValue", "disabled", "value"])) : createCommentVNode("", true),
        renderSlot(_ctx.$slots, "default", {}, () => [
          createTextVNode(toDisplayString(__props.label), 1)
        ])
      ], 2)), [
        [vShow, unref(display)]
      ]);
    };
  }
});
const component = withInstall(_sfc_main);
export { _sfc_main as _, component as c };
