"use strict";
const vue = require("vue");
const useFormSelect = require("./useFormSelect-BrveyBvf.js");
const useDefaults = require("./useDefaults-YXpmugKp.js");
const useAriaInvalid = require("./useAriaInvalid-Caxf1WW4.js");
const index = require("./index-C_bsiScj.js");
const useId = require("./useId-Dl8Hi5_U.js");
const useStateClass = require("./useStateClass-Bk6-veG2.js");
const keys = require("./keys-D70E9HED.js");
const index$1 = require("./index-JJEBhaXq.js");
const _hoisted_1$1 = ["label"];
const _sfc_main$2 = /* @__PURE__ */ vue.defineComponent({
  __name: "BFormSelectOptionGroup",
  props: {
    disabledField: { default: "disabled" },
    label: { default: void 0 },
    options: { default: () => [] },
    textField: { default: "text" },
    valueField: { default: "value" }
  },
  setup(__props) {
    const _props = __props;
    const props = useDefaults.useDefaults(_props, "BFormSelectOptionGroup");
    const { normalizedOptions } = useFormSelect.useFormSelect(() => props.options, props);
    return (_ctx, _cache) => {
      return vue.openBlock(), vue.createElementBlock("optgroup", {
        label: vue.unref(props).label
      }, [
        vue.renderSlot(_ctx.$slots, "first"),
        (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(vue.unref(normalizedOptions), (option, index2) => {
          return vue.openBlock(), vue.createBlock(useFormSelect._sfc_main, vue.mergeProps({ key: index2 }, { ref_for: true }, { ..._ctx.$attrs, ...option }), {
            default: vue.withCtx(() => [
              vue.renderSlot(_ctx.$slots, "option", vue.mergeProps({ ref_for: true }, option), () => [
                vue.createTextVNode(vue.toDisplayString(option.text), 1)
              ])
            ]),
            _: 2
          }, 1040);
        }), 128)),
        vue.renderSlot(_ctx.$slots, "default")
      ], 8, _hoisted_1$1);
    };
  }
});
const _hoisted_1 = ["id", "name", "form", "multiple", "size", "disabled", "required", "aria-required", "aria-invalid"];
const _sfc_main$1 = /* @__PURE__ */ vue.defineComponent({
  __name: "BFormSelectBase",
  props: /* @__PURE__ */ vue.mergeModels({
    ariaInvalid: { type: [Boolean, String], default: void 0 },
    autofocus: { type: Boolean, default: false },
    disabled: { type: Boolean, default: false },
    disabledField: { default: "disabled" },
    form: { default: void 0 },
    id: { default: void 0 },
    labelField: { default: "label" },
    multiple: { type: Boolean, default: false },
    name: { default: void 0 },
    options: { default: () => [] },
    optionsField: { default: "options" },
    plain: { type: Boolean, default: false },
    required: { type: Boolean, default: false },
    selectSize: { default: 0 },
    size: { default: "md" },
    state: { type: [Boolean, null], default: null },
    textField: { default: "text" },
    valueField: { default: "value" }
  }, {
    "modelValue": {
      default: ""
    },
    "modelModifiers": {}
  }),
  emits: ["update:modelValue"],
  setup(__props, { expose: __expose }) {
    const _props = __props;
    const props = useDefaults.useDefaults(_props, "BFormSelect");
    const modelValue = vue.useModel(__props, "modelValue");
    const computedId = useId.useId(() => props.id, "input");
    const formGroupData = vue.inject(keys.formGroupKey, null)?.(computedId);
    const isDisabled = vue.computed(() => props.disabled || (formGroupData?.disabled.value ?? false));
    const selectSizeNumber = index$1.useToNumber(() => props.selectSize);
    const stateClass = useStateClass.useStateClass(() => props.state);
    const input = vue.useTemplateRef("_input");
    const { focused } = index.useFocus(input, {
      initialValue: props.autofocus
    });
    const computedClasses = vue.computed(() => [
      stateClass.value,
      {
        "form-control": props.plain,
        [`form-control-${props.size}`]: props.size !== "md" && props.plain,
        "form-select": !props.plain,
        [`form-select-${props.size}`]: props.size !== "md" && !props.plain
      }
    ]);
    const computedSelectSize = vue.computed(
      () => !props.plain && selectSizeNumber.value > 0 ? selectSizeNumber.value : void 0
    );
    const computedAriaInvalid = useAriaInvalid.useAriaInvalid(
      () => props.ariaInvalid,
      () => props.state
    );
    const { normalizedOptions, isComplex } = useFormSelect.useFormSelect(() => props.options, props);
    const normalizedOptsWrapper = vue.computed(() => normalizedOptions.value);
    const localValue = vue.computed({
      get: () => modelValue.value,
      set: (newValue) => {
        modelValue.value = newValue;
      }
    });
    vue.provide(keys.formSelectKey, {
      modelValue: vue.readonly(localValue)
    });
    __expose({
      blur: () => {
        focused.value = false;
      },
      element: input,
      focus: () => {
        focused.value = true;
      }
    });
    return (_ctx, _cache) => {
      return vue.withDirectives((vue.openBlock(), vue.createElementBlock("select", {
        id: vue.unref(computedId),
        ref: "_input",
        "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => localValue.value = $event),
        class: vue.normalizeClass(computedClasses.value),
        name: vue.unref(props).name,
        form: vue.unref(props).form || void 0,
        multiple: vue.unref(props).multiple || void 0,
        size: computedSelectSize.value,
        disabled: isDisabled.value,
        required: vue.unref(props).required || void 0,
        "aria-required": vue.unref(props).required || void 0,
        "aria-invalid": vue.unref(computedAriaInvalid)
      }, [
        vue.renderSlot(_ctx.$slots, "first"),
        (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(normalizedOptsWrapper.value, (option, index2) => {
          return vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: index2 }, [
            vue.unref(isComplex)(option) ? (vue.openBlock(), vue.createBlock(_sfc_main$2, {
              key: 0,
              label: option.label,
              options: option.options,
              "value-field": vue.unref(props).valueField,
              "text-field": vue.unref(props).textField,
              "disabled-field": vue.unref(props).disabledField
            }, null, 8, ["label", "options", "value-field", "text-field", "disabled-field"])) : (vue.openBlock(), vue.createBlock(useFormSelect._sfc_main, vue.mergeProps({
              key: 1,
              ref_for: true
            }, option), {
              default: vue.withCtx(() => [
                vue.renderSlot(_ctx.$slots, "option", vue.mergeProps({ ref_for: true }, option), () => [
                  vue.createTextVNode(vue.toDisplayString(option.text), 1)
                ])
              ]),
              _: 2
            }, 1040))
          ], 64);
        }), 128)),
        vue.renderSlot(_ctx.$slots, "default")
      ], 10, _hoisted_1)), [
        [vue.vModelSelect, localValue.value]
      ]);
    };
  }
});
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
  __name: "BFormSelect",
  props: /* @__PURE__ */ vue.mergeModels({
    ariaInvalid: { type: [Boolean, String], default: void 0 },
    autofocus: { type: Boolean, default: false },
    disabled: { type: Boolean, default: false },
    disabledField: { default: "disabled" },
    form: { default: void 0 },
    id: { default: void 0 },
    labelField: { default: "label" },
    multiple: { type: Boolean, default: false },
    name: { default: void 0 },
    options: { default: () => [] },
    optionsField: { default: "options" },
    plain: { type: Boolean, default: false },
    required: { type: Boolean, default: false },
    selectSize: { default: 0 },
    size: { default: "md" },
    state: { type: [Boolean, null], default: null },
    textField: { default: "text" },
    valueField: { default: "value" }
  }, {
    "modelValue": {
      // eslint-disable-next-line @typescript-eslint/no-explicit-any
      default: ""
    },
    "modelModifiers": {}
  }),
  emits: ["update:modelValue"],
  setup(__props) {
    const props = __props;
    const modelValue = vue.useModel(__props, "modelValue");
    const normalizeSimpleOption = (el) => ({
      ...el,
      value: el[props.valueField],
      text: el[props.textField] ?? "",
      disabled: el[props.disabledField] ?? false
    });
    const normalizePrimitive = (el) => ({ value: el, text: String(el), disabled: false });
    const normalizedOptions = vue.computed(() => {
      const optionsArray = props.options ?? [];
      const hasComplexOptions = optionsArray.some(
        (el) => typeof el !== "string" && typeof el !== "number" && typeof el !== "boolean" && el[props.optionsField] !== void 0
      );
      if (hasComplexOptions) {
        return optionsArray.map((el) => {
          if (typeof el === "string" || typeof el === "number" || typeof el === "boolean") {
            return normalizePrimitive(el);
          }
          const optionsField = el[props.optionsField];
          if (optionsField !== void 0 && Array.isArray(optionsField)) {
            const label = el[props.labelField] ?? el[props.textField] ?? "";
            return {
              label,
              options: optionsField.map((subOpt) => {
                if (typeof subOpt === "string" || typeof subOpt === "number" || typeof subOpt === "boolean") {
                  return normalizePrimitive(subOpt);
                }
                return normalizeSimpleOption(subOpt);
              })
            };
          }
          return normalizeSimpleOption(el);
        });
      }
      return optionsArray.map((el) => {
        if (typeof el === "string" || typeof el === "number" || typeof el === "boolean") {
          return normalizePrimitive(el);
        }
        return normalizeSimpleOption(el);
      });
    });
    const forwardedProps = vue.computed(() => ({
      ariaInvalid: props.ariaInvalid,
      autofocus: props.autofocus,
      disabled: props.disabled,
      form: props.form,
      id: props.id,
      multiple: props.multiple,
      name: props.name,
      plain: props.plain,
      required: props.required,
      selectSize: props.selectSize,
      size: props.size,
      state: props.state
    }));
    return (_ctx, _cache) => {
      return vue.openBlock(), vue.createBlock(_sfc_main$1, vue.mergeProps(forwardedProps.value, {
        modelValue: modelValue.value,
        "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => modelValue.value = $event),
        options: normalizedOptions.value
      }), {
        first: vue.withCtx(() => [
          vue.renderSlot(_ctx.$slots, "first")
        ]),
        option: vue.withCtx((slotProps) => [
          vue.renderSlot(_ctx.$slots, "option", vue.normalizeProps(vue.guardReactiveProps(slotProps)))
        ]),
        default: vue.withCtx(() => [
          vue.renderSlot(_ctx.$slots, "default")
        ]),
        _: 3
      }, 16, ["modelValue", "options"]);
    };
  }
});
exports._sfc_main = _sfc_main;
exports._sfc_main$1 = _sfc_main$2;
//# sourceMappingURL=BFormSelect.vue_vue_type_script_setup_true_lang-BoyetQpE.js.map
