import { defineComponent, inject, computed, createElementBlock, openBlock, mergeProps, unref, renderSlot, toValue } from "vue";
import { u as useDefaults } from "./useDefaults-DvqfKEoD.mjs";
import { k as formSelectKey } from "./keys-D5Pj1dmf.mjs";
import { g as get } from "./object-hfadz3TY.mjs";
const _hoisted_1 = ["value", "disabled", "selected"];
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "BFormSelectOption",
  props: {
    disabled: { type: Boolean, default: false },
    value: { default: void 0 }
  },
  setup(__props) {
    const _props = __props;
    const props = useDefaults(_props, "BFormSelectOption");
    const formSelectContext = inject(formSelectKey, null);
    const isSelected = computed(() => {
      if (!formSelectContext) return false;
      return formSelectContext.modelValue.value === props.value;
    });
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("option", mergeProps({
        value: unref(props).value,
        disabled: unref(props).disabled,
        selected: isSelected.value
      }, _ctx.$attrs), [
        renderSlot(_ctx.$slots, "default")
      ], 16, _hoisted_1);
    };
  }
});
const useFormSelect = (options, props) => {
  const isComplex = (option) => typeof option === "object" && option !== null && "options" in option;
  const normalizeOption = (option) => {
    const propsValue = toValue(props);
    if (typeof option === "string") {
      return { value: option, text: option };
    }
    if (typeof option === "number") {
      return { value: option, text: `${option}` };
    }
    if (option instanceof Date) {
      return { value: option, text: option.toLocaleString() };
    }
    const value = get(option, propsValue.valueField);
    const text = get(option, propsValue.textField);
    const disabled = get(option, propsValue.disabledField);
    const opts = propsValue.optionsField ? get(option, propsValue.optionsField) : void 0;
    if (opts !== void 0) {
      return {
        label: get(option, propsValue.labelField) || text,
        options: opts
      };
    }
    return {
      ...typeof option === "object" ? option : void 0,
      value,
      text,
      disabled
    };
  };
  const normalizeOptions = (opts) => opts.map((option) => normalizeOption(option));
  const normalizedOptions = computed(() => normalizeOptions(toValue(options)));
  return { normalizedOptions, isComplex };
};
export {
  _sfc_main as _,
  useFormSelect as u
};
//# sourceMappingURL=useFormSelect-BzzYkH_f.mjs.map
