import { defineComponent, mergeModels, useSlots, useModel, inject, useTemplateRef, computed, createBlock, openBlock, normalizeClass, unref, withCtx, withDirectives, createElementBlock, createCommentVNode, createElementVNode, mergeProps, vModelRadio, renderSlot, provide, toRef, Fragment, renderList, createTextVNode, toDisplayString, normalizeProps, guardReactiveProps } from "vue";
import { u as radioGroupKey, j as formGroupKey } from "./keys-D5Pj1dmf.mjs";
import { c as useFocus } from "./index-nMtnPEP0.mjs";
import { g as getClasses, a as getInputClasses, b as getLabelClasses, c as getGroupAttr, d as getGroupClasses } from "./useFormCheck-BWqaIHhT.mjs";
import { i as isEmptySlot } from "./dom-DVb-f0ZG.mjs";
import { _ as _sfc_main$3 } from "./ConditionalWrapper.vue_vue_type_script_lang-IX_NpHH-.mjs";
import { u as useDefaults } from "./useDefaults-DvqfKEoD.mjs";
import { u as useId } from "./useId-9_HUwM96.mjs";
const _hoisted_1$1 = ["id", "disabled", "required", "name", "form", "aria-label", "aria-labelledby", "value", "aria-required"];
const _hoisted_2 = ["for"];
const _sfc_main$2 = /* @__PURE__ */ defineComponent({
  ...{
    inheritAttrs: false
  },
  __name: "BFormRadio",
  props: /* @__PURE__ */ mergeModels({
    ariaLabel: { default: void 0 },
    ariaLabelledby: { default: void 0 },
    autofocus: { type: Boolean, default: false },
    button: { type: Boolean, default: void 0 },
    buttonGroup: { type: Boolean, default: false },
    buttonVariant: { default: void 0 },
    disabled: { type: Boolean, default: false },
    form: { default: void 0 },
    id: { default: void 0 },
    inline: { type: Boolean, default: void 0 },
    name: { default: void 0 },
    plain: { type: Boolean, default: void 0 },
    required: { type: Boolean, default: false },
    reverse: { type: Boolean, default: void 0 },
    size: { default: void 0 },
    state: { type: [Boolean, null], default: void 0 },
    value: { type: [Boolean, String, Array, Object, Number, null], default: true }
  }, {
    "modelValue": { type: [Boolean, String, Array, Object, Number, null], ...{
      default: void 0
    } },
    "modelModifiers": {}
  }),
  emits: ["update:modelValue"],
  setup(__props, { expose: __expose }) {
    const _props = __props;
    const props = useDefaults(_props, "BFormRadio");
    const slots = useSlots();
    const modelValue = useModel(__props, "modelValue");
    const computedId = useId(() => props.id, "form-check");
    const parentData = inject(radioGroupKey, null);
    const formGroupData = inject(formGroupKey, null)?.(computedId);
    const input = useTemplateRef("_input");
    const { focused } = useFocus(input, {
      initialValue: props.autofocus
    });
    const hasDefaultSlot = computed(() => !isEmptySlot(slots.default));
    const propDefaults = {
      plain: false,
      button: false,
      inline: false,
      reverse: false,
      size: "md",
      buttonVariant: "secondary",
      state: null
    };
    const resolvedProps = computed(() => ({
      plain: props.plain ?? parentData?.plain.value ?? propDefaults.plain,
      button: props.button ?? parentData?.buttons.value ?? propDefaults.button,
      inline: props.inline ?? parentData?.inline.value ?? propDefaults.inline,
      reverse: props.reverse ?? parentData?.reverse.value ?? propDefaults.reverse,
      state: props.state ?? parentData?.state.value ?? propDefaults.state,
      size: props.size ?? parentData?.size.value ?? propDefaults.size,
      buttonVariant: props.buttonVariant ?? parentData?.buttonVariant.value ?? propDefaults.buttonVariant
    }));
    const resolvedPlain = computed(() => resolvedProps.value.plain);
    const localValue = computed({
      get: () => parentData ? parentData.modelValue.value : modelValue.value,
      set: (newValue) => {
        if (newValue === void 0) return;
        if (parentData !== null) {
          parentData.modelValue.value = newValue;
          return;
        }
        modelValue.value = newValue;
      }
    });
    const computedRequired = computed(
      () => !!(props.name ?? parentData?.name.value) && (props.required || parentData?.required.value)
    );
    const isButtonGroup = computed(() => props.buttonGroup || (parentData?.buttons.value ?? false));
    const classesObject = computed(() => ({
      ...resolvedProps.value,
      hasDefaultSlot: hasDefaultSlot.value
    }));
    const computedClasses = getClasses(classesObject);
    const inputClasses = getInputClasses(classesObject);
    const labelClasses = getLabelClasses(classesObject);
    __expose({
      blur: () => {
        focused.value = false;
      },
      element: input,
      focus: () => {
        focused.value = true;
      }
    });
    return (_ctx, _cache) => {
      return openBlock(), createBlock(_sfc_main$3, {
        skip: isButtonGroup.value,
        class: normalizeClass(unref(computedClasses))
      }, {
        default: withCtx(() => [
          withDirectives(createElementVNode("input", mergeProps({ id: unref(computedId) }, _ctx.$attrs, {
            ref: "_input",
            "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => localValue.value = $event),
            class: unref(inputClasses),
            type: "radio",
            disabled: unref(props).disabled || unref(parentData)?.disabled.value || unref(formGroupData)?.disabled.value,
            required: computedRequired.value || void 0,
            name: unref(props).name || unref(parentData)?.name.value,
            form: unref(props).form || unref(parentData)?.form.value,
            "aria-label": unref(props).ariaLabel,
            "aria-labelledby": unref(props).ariaLabelledby,
            value: unref(props).value,
            "aria-required": computedRequired.value || void 0
          }), null, 16, _hoisted_1$1), [
            [vModelRadio, localValue.value]
          ]),
          hasDefaultSlot.value || !resolvedPlain.value ? (openBlock(), createElementBlock("label", {
            key: 0,
            for: unref(computedId),
            class: normalizeClass(unref(labelClasses))
          }, [
            renderSlot(_ctx.$slots, "default")
          ], 10, _hoisted_2)) : createCommentVNode("", true)
        ]),
        _: 3
      }, 8, ["skip", "class"]);
    };
  }
});
const _hoisted_1 = ["id"];
const _sfc_main$1 = /* @__PURE__ */ defineComponent({
  __name: "BFormRadioGroupBase",
  props: /* @__PURE__ */ mergeModels({
    ariaInvalid: { type: [Boolean, String], default: void 0 },
    autofocus: { type: Boolean, default: false },
    buttonVariant: { default: "secondary" },
    buttons: { type: Boolean, default: false },
    disabled: { type: Boolean, default: false },
    form: { default: void 0 },
    id: { default: void 0 },
    name: { default: void 0 },
    options: { default: () => [] },
    plain: { type: Boolean, default: false },
    required: { type: Boolean, default: false },
    reverse: { type: Boolean, default: false },
    size: { default: "md" },
    stacked: { type: Boolean, default: false },
    state: { type: [Boolean, null], default: null },
    validated: { type: Boolean, default: false }
  }, {
    "modelValue": {
      default: null
    },
    "modelModifiers": {}
  }),
  emits: ["update:modelValue"],
  setup(__props, { expose: __expose }) {
    const _props = __props;
    const props = useDefaults(_props, "BFormRadioGroup");
    const modelValue = useModel(__props, "modelValue");
    const computedId = useId(() => props.id, "radio");
    const computedName = useId(() => props.name, "radio");
    const element = useTemplateRef("_element");
    const { focused } = useFocus(element, {
      initialValue: props.autofocus
    });
    const normalizedOptions = computed(
      () => props.options.map((option) => {
        if (typeof option === "object" && option !== null) {
          return {
            ...option,
            disabled: props.disabled ? true : option.disabled ?? false
          };
        }
        return {
          text: String(option),
          value: option,
          disabled: props.disabled ? true : false
        };
      })
    );
    provide(radioGroupKey, {
      modelValue,
      buttonVariant: toRef(() => props.buttonVariant),
      form: toRef(() => props.form),
      name: computedName,
      buttons: toRef(() => props.buttons),
      state: toRef(() => props.state),
      plain: toRef(() => props.plain),
      size: toRef(() => props.size),
      inline: toRef(() => !props.stacked),
      reverse: toRef(() => props.reverse),
      required: toRef(() => props.required),
      disabled: toRef(() => props.disabled)
    });
    const classesObject = computed(() => ({
      required: props.required,
      ariaInvalid: props.ariaInvalid,
      state: props.state,
      validated: props.validated,
      buttons: props.buttons,
      stacked: props.stacked,
      size: props.size
    }));
    const computedAttrs = getGroupAttr(classesObject);
    const computedClasses = getGroupClasses(classesObject);
    __expose({
      blur: () => {
        focused.value = false;
      },
      focus: () => {
        focused.value = true;
      }
    });
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", mergeProps(unref(computedAttrs), {
        id: unref(computedId),
        ref: "_element",
        role: "radiogroup",
        class: [unref(computedClasses), "bv-no-focus-ring"],
        tabindex: "-1"
      }), [
        renderSlot(_ctx.$slots, "first"),
        (openBlock(true), createElementBlock(Fragment, null, renderList(normalizedOptions.value, (item, index) => {
          return openBlock(), createBlock(_sfc_main$2, mergeProps({ key: index }, { ref_for: true }, item), {
            default: withCtx(() => [
              renderSlot(_ctx.$slots, "option", mergeProps({ ref_for: true }, item), () => [
                createTextVNode(toDisplayString(item.text), 1)
              ])
            ]),
            _: 2
          }, 1040);
        }), 128)),
        renderSlot(_ctx.$slots, "default")
      ], 16, _hoisted_1);
    };
  }
});
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "BFormRadioGroup",
  props: /* @__PURE__ */ mergeModels({
    ariaInvalid: { type: [Boolean, String], default: void 0 },
    autofocus: { type: Boolean, default: false },
    buttonVariant: { default: "secondary" },
    buttons: { type: Boolean, default: false },
    disabled: { type: Boolean, default: false },
    disabledField: { default: "disabled" },
    form: { default: void 0 },
    id: { default: void 0 },
    name: { default: void 0 },
    options: { default: () => [] },
    plain: { type: Boolean, default: false },
    required: { type: Boolean, default: false },
    reverse: { type: Boolean, default: false },
    size: { default: "md" },
    stacked: { type: Boolean, default: false },
    state: { type: [Boolean, null], default: null },
    textField: { default: "text" },
    validated: { type: Boolean, default: false },
    valueField: { default: "value" }
  }, {
    "modelValue": {
      // eslint-disable-next-line @typescript-eslint/no-explicit-any
      default: void 0
    },
    "modelModifiers": {}
  }),
  emits: ["update:modelValue"],
  setup(__props) {
    const props = __props;
    const modelValue = useModel(__props, "modelValue");
    const normalizedOptions = computed(
      () => (props.options ?? []).map(
        (el) => typeof el === "string" || typeof el === "number" || typeof el === "boolean" ? {
          value: el,
          disabled: props.disabled,
          text: el.toString()
        } : {
          value: el[props.valueField],
          disabled: props.disabled || (el[props.disabledField] ?? false),
          text: el[props.textField] ?? ""
        }
      )
    );
    const forwardedProps = computed(() => ({
      id: props.id,
      name: props.name,
      size: props.size,
      state: props.state,
      buttonVariant: props.buttonVariant,
      buttons: props.buttons,
      stacked: props.stacked,
      disabled: props.disabled,
      required: props.required,
      validated: props.validated,
      autofocus: props.autofocus,
      form: props.form,
      ariaInvalid: props.ariaInvalid,
      plain: props.plain,
      reverse: props.reverse
    }));
    return (_ctx, _cache) => {
      return openBlock(), createBlock(_sfc_main$1, mergeProps(forwardedProps.value, {
        modelValue: modelValue.value,
        "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => modelValue.value = $event),
        options: normalizedOptions.value
      }), {
        first: withCtx(() => [
          renderSlot(_ctx.$slots, "first")
        ]),
        option: withCtx((slotProps) => [
          renderSlot(_ctx.$slots, "option", normalizeProps(guardReactiveProps(slotProps)))
        ]),
        default: withCtx(() => [
          renderSlot(_ctx.$slots, "default")
        ]),
        _: 3
      }, 16, ["modelValue", "options"]);
    };
  }
});
export {
  _sfc_main$2 as _,
  _sfc_main as a
};
//# sourceMappingURL=BFormRadioGroup.vue_vue_type_script_setup_true_lang-B0h6Lzai.mjs.map
