"use strict";
const vue = require("vue");
const index = require("./index-C_bsiScj.js");
const useFormCheck = require("./useFormCheck-BKc2jzu9.js");
const keys = require("./keys-D70E9HED.js");
const ConditionalWrapper_vue_vue_type_script_lang = require("./ConditionalWrapper.vue_vue_type_script_lang-CFfEbslT.js");
const dom = require("./dom-BgEUZpKg.js");
const useDefaults = require("./useDefaults-YXpmugKp.js");
const useId = require("./useId-Dl8Hi5_U.js");
const _hoisted_1$1 = ["id", "disabled", "required", "name", "form", "aria-label", "aria-labelledby", "aria-required", "value", "true-value", "false-value", "indeterminate"];
const _hoisted_2 = ["for"];
const _sfc_main$2 = /* @__PURE__ */ vue.defineComponent({
  ...{
    inheritAttrs: false
  },
  __name: "BFormCheckbox",
  props: /* @__PURE__ */ vue.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 },
    switch: { type: Boolean, default: void 0 },
    uncheckedValue: { type: [Array, Set, String, Boolean, Object, Number, null], default: false },
    wrapperAttrs: { default: void 0 },
    inputClass: { default: void 0 },
    value: { type: [String, Boolean, Array, Set, Object, Number, null], default: true }
  }, {
    "modelValue": { type: [Array, Set, String, Boolean, Object, Number, null], ...{
      default: void 0
    } },
    "modelModifiers": {},
    "indeterminate": { type: Boolean, ...{
      default: false
    } },
    "indeterminateModifiers": {}
  }),
  emits: ["update:modelValue", "update:indeterminate"],
  setup(__props, { expose: __expose }) {
    const _props = __props;
    const props = useDefaults.useDefaults(_props, "BFormCheckbox");
    const slots = vue.useSlots();
    const attrs = vue.useAttrs();
    const modelValue = vue.useModel(__props, "modelValue");
    const indeterminate = vue.useModel(
      __props,
      "indeterminate"
    );
    const processedAttrs = vue.computed(() => {
      const { class: wrapperClass, ...inputAttrs } = attrs;
      return { wrapperClass, inputAttrs };
    });
    const computedId = useId.useId(() => props.id, "form-check");
    const parentData = vue.inject(keys.checkboxGroupKey, null);
    const formGroupData = vue.inject(keys.formGroupKey, null)?.(computedId);
    const input = vue.useTemplateRef("_input");
    const { focused } = index.useFocus(input, {
      initialValue: props.autofocus
    });
    const hasDefaultSlot = vue.computed(() => !dom.isEmptySlot(slots.default));
    const propDefaults = {
      plain: false,
      button: false,
      inline: false,
      reverse: false,
      switch: false,
      size: "md",
      buttonVariant: "secondary",
      state: null
    };
    const resolvedProps = vue.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,
      switch: props.switch ?? parentData?.switch.value ?? propDefaults.switch,
      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 = vue.computed(() => resolvedProps.value.plain);
    const localValue = vue.computed({
      get: () => parentData ? parentData.modelValue.value : modelValue.value,
      set: (newVal) => {
        if (newVal === void 0) return;
        indeterminate.value = false;
        if (parentData !== null && Array.isArray(newVal)) {
          parentData.modelValue.value = newVal;
          return;
        }
        modelValue.value = newVal;
      }
    });
    const computedRequired = vue.computed(
      () => !!(props.name ?? parentData?.name.value) && (props.required || parentData?.required.value)
    );
    const isButtonGroup = vue.computed(() => props.buttonGroup || (parentData?.buttons.value ?? false));
    const classesObject = vue.computed(() => ({
      ...resolvedProps.value,
      hasDefaultSlot: hasDefaultSlot.value
    }));
    const wrapperClasses = useFormCheck.getClasses(classesObject);
    const computedWrapperClasses = vue.computed(() => [
      wrapperClasses.value,
      processedAttrs.value.wrapperClass
    ]);
    const inputClasses = useFormCheck.getInputClasses(classesObject);
    const computedInputClasses = vue.computed(() => [inputClasses.value, props.inputClass]);
    const labelClasses = useFormCheck.getLabelClasses(classesObject);
    __expose({
      blur: () => {
        focused.value = false;
      },
      element: input,
      focus: () => {
        focused.value = true;
      }
    });
    return (_ctx, _cache) => {
      return vue.openBlock(), vue.createBlock(ConditionalWrapper_vue_vue_type_script_lang._sfc_main, vue.mergeProps({ skip: isButtonGroup.value }, vue.unref(props).wrapperAttrs, { class: computedWrapperClasses.value }), {
        default: vue.withCtx(() => [
          vue.withDirectives(vue.createElementVNode("input", vue.mergeProps({
            id: vue.unref(computedId),
            ref: "_input",
            "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => localValue.value = $event),
            class: computedInputClasses.value,
            type: "checkbox",
            disabled: vue.unref(props).disabled || vue.unref(parentData)?.disabled.value || vue.unref(formGroupData)?.disabled.value,
            required: computedRequired.value || void 0,
            name: vue.unref(props).name || vue.unref(parentData)?.name.value,
            form: vue.unref(props).form || vue.unref(parentData)?.form.value,
            "aria-label": vue.unref(props).ariaLabel,
            "aria-labelledby": vue.unref(props).ariaLabelledby,
            "aria-required": computedRequired.value || void 0,
            value: vue.unref(props).value,
            "true-value": vue.unref(props).value,
            "false-value": vue.unref(props).uncheckedValue,
            indeterminate: indeterminate.value || void 0
          }, processedAttrs.value.inputAttrs), null, 16, _hoisted_1$1), [
            [vue.vModelCheckbox, localValue.value]
          ]),
          hasDefaultSlot.value || !resolvedPlain.value ? (vue.openBlock(), vue.createElementBlock("label", {
            key: 0,
            for: vue.unref(computedId),
            class: vue.normalizeClass(vue.unref(labelClasses))
          }, [
            vue.renderSlot(_ctx.$slots, "default")
          ], 10, _hoisted_2)) : vue.createCommentVNode("", true)
        ]),
        _: 3
      }, 16, ["skip", "class"]);
    };
  }
});
const _hoisted_1 = ["id"];
const _sfc_main$1 = /* @__PURE__ */ vue.defineComponent({
  __name: "BFormCheckboxGroupBase",
  props: /* @__PURE__ */ vue.mergeModels({
    id: { default: void 0 },
    name: { default: void 0 },
    size: { default: "md" },
    state: { type: [Boolean, null], default: null },
    buttonVariant: { default: "secondary" },
    buttons: { type: Boolean, default: false },
    stacked: { type: Boolean, default: false },
    disabled: { type: Boolean, default: false },
    required: { type: Boolean, default: false },
    validated: { type: Boolean, default: false },
    autofocus: { type: Boolean, default: false },
    form: { default: void 0 },
    ariaInvalid: { type: [Boolean, String], default: void 0 },
    plain: { type: Boolean, default: false },
    reverse: { type: Boolean, default: false },
    switches: { type: Boolean, default: false },
    options: { default: () => [] }
  }, {
    "modelValue": {
      default: () => []
    },
    "modelModifiers": {}
  }),
  emits: ["update:modelValue"],
  setup(__props, { expose: __expose }) {
    const _props = __props;
    const props = useDefaults.useDefaults(_props, "BFormCheckboxGroup");
    const modelValue = vue.useModel(__props, "modelValue");
    const computedId = useId.useId(() => props.id, "checkbox");
    const computedName = useId.useId(() => props.name, "checkbox");
    const _element = vue.useTemplateRef("_element");
    const { focused } = index.useFocus(_element, {
      initialValue: props.autofocus
    });
    vue.provide(keys.checkboxGroupKey, {
      modelValue,
      switch: vue.toRef(() => props.switches),
      buttonVariant: vue.toRef(() => props.buttonVariant),
      form: vue.toRef(() => props.form),
      name: computedName,
      state: vue.toRef(() => props.state),
      plain: vue.toRef(() => props.plain),
      size: vue.toRef(() => props.size),
      inline: vue.toRef(() => !props.stacked),
      reverse: vue.toRef(() => props.reverse),
      required: vue.toRef(() => props.required),
      buttons: vue.toRef(() => props.buttons),
      disabled: vue.toRef(() => props.disabled)
    });
    const normalizedOptions = vue.computed(
      () => props.options.map((option) => {
        if (typeof option === "object" && option !== null) {
          return {
            ...option,
            text: option.text ?? String(option.value ?? ""),
            value: option.value ?? null,
            disabled: props.disabled ? true : option.disabled ?? false
          };
        }
        return {
          text: String(option),
          value: option,
          disabled: props.disabled ? true : false
        };
      })
    );
    const classesObject = vue.computed(() => ({
      required: props.required,
      ariaInvalid: props.ariaInvalid,
      state: props.state,
      validated: props.validated,
      buttons: props.buttons,
      stacked: props.stacked,
      size: props.size
    }));
    const attrs = useFormCheck.getGroupAttr(classesObject);
    const classes = useFormCheck.getGroupClasses(classesObject);
    __expose({
      blur: () => {
        focused.value = false;
      },
      focus: () => {
        focused.value = true;
      }
    });
    return (_ctx, _cache) => {
      return vue.openBlock(), vue.createElementBlock("div", vue.mergeProps(vue.unref(attrs), {
        id: vue.unref(computedId),
        ref_key: "_element",
        ref: _element,
        role: "group",
        class: [vue.unref(classes), "bv-no-focus-ring"],
        tabindex: "-1"
      }), [
        vue.renderSlot(_ctx.$slots, "first"),
        (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(normalizedOptions.value, (item, index2) => {
          return vue.openBlock(), vue.createBlock(_sfc_main$2, vue.mergeProps({ key: index2 }, { ref_for: true }, item), {
            default: vue.withCtx(() => [
              vue.renderSlot(_ctx.$slots, "option", vue.mergeProps({ ref_for: true }, item), () => [
                vue.createTextVNode(vue.toDisplayString(item.text), 1)
              ])
            ]),
            _: 2
          }, 1040);
        }), 128)),
        vue.renderSlot(_ctx.$slots, "default")
      ], 16, _hoisted_1);
    };
  }
});
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
  __name: "BFormCheckboxGroup",
  props: /* @__PURE__ */ vue.mergeModels({
    options: { default: () => [] },
    valueField: { default: "value" },
    textField: { default: "text" },
    disabledField: { default: "disabled" },
    id: { default: void 0 },
    name: { default: void 0 },
    size: { default: "md" },
    state: { type: [Boolean, null], default: null },
    buttonVariant: { default: "secondary" },
    buttons: { type: Boolean, default: false },
    stacked: { type: Boolean, default: false },
    disabled: { type: Boolean, default: false },
    required: { type: Boolean, default: false },
    validated: { type: Boolean, default: false },
    autofocus: { type: Boolean, default: false },
    form: { default: void 0 },
    ariaInvalid: { type: [Boolean, String], default: void 0 },
    plain: { type: Boolean, default: false },
    reverse: { type: Boolean, default: false },
    switches: { type: Boolean, default: false }
  }, {
    "modelValue": {
      default: () => []
    },
    "modelModifiers": {}
  }),
  emits: ["update:modelValue"],
  setup(__props) {
    const props = __props;
    const modelValue = vue.useModel(__props, "modelValue");
    const normalizedOptions = vue.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] ?? String(el[props.valueField])
        }
      )
    );
    const forwardedProps = vue.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,
      switches: props.switches
    }));
    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$2;
exports._sfc_main$1 = _sfc_main;
//# sourceMappingURL=BFormCheckboxGroup.vue_vue_type_script_setup_true_lang-N5b24asj.js.map
