"use strict";
const vue = require("vue");
const useDefaults = require("./useDefaults-YXpmugKp.js");
const keys = require("./keys-D70E9HED.js");
const object = require("./object-DlOVrM-t.js");
const _hoisted_1 = ["value", "disabled", "selected"];
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
  __name: "BFormSelectOption",
  props: {
    disabled: { type: Boolean, default: false },
    value: { default: void 0 }
  },
  setup(__props) {
    const _props = __props;
    const props = useDefaults.useDefaults(_props, "BFormSelectOption");
    const formSelectContext = vue.inject(keys.formSelectKey, null);
    const isSelected = vue.computed(() => {
      if (!formSelectContext) return false;
      return formSelectContext.modelValue.value === props.value;
    });
    return (_ctx, _cache) => {
      return vue.openBlock(), vue.createElementBlock("option", vue.mergeProps({
        value: vue.unref(props).value,
        disabled: vue.unref(props).disabled,
        selected: isSelected.value
      }, _ctx.$attrs), [
        vue.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 = vue.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 = object.get(option, propsValue.valueField);
    const text = object.get(option, propsValue.textField);
    const disabled = object.get(option, propsValue.disabledField);
    const opts = propsValue.optionsField ? object.get(option, propsValue.optionsField) : void 0;
    if (opts !== void 0) {
      return {
        label: object.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 = vue.computed(() => normalizeOptions(vue.toValue(options)));
  return { normalizedOptions, isComplex };
};
exports._sfc_main = _sfc_main;
exports.useFormSelect = useFormSelect;
//# sourceMappingURL=useFormSelect-BrveyBvf.js.map
