"use strict";
const vue = require("vue");
const useAriaInvalid = require("./useAriaInvalid-Caxf1WW4.js");
const dom = require("./dom-BgEUZpKg.js");
const BCol_vue_vue_type_script_setup_true_lang = require("./BCol.vue_vue_type_script_setup_true_lang-CbLgA_3t.js");
const BFormValidFeedback_vue_vue_type_script_setup_true_lang = require("./BFormValidFeedback.vue_vue_type_script_setup_true_lang-CT60Swxy.js");
const stringUtils = require("./stringUtils-DVq7fDaW.js");
const useStateClass = require("./useStateClass-Bk6-veG2.js");
const useId = require("./useId-Dl8Hi5_U.js");
const index = require("./index-C_bsiScj.js");
const useDefaults = require("./useDefaults-YXpmugKp.js");
const keys = require("./keys-D70E9HED.js");
const suffixPropName = (suffix, value) => value + (suffix ? stringUtils.upperFirst(suffix) : "");
const _hoisted_1 = {
  key: 0,
  ref: "_content",
  class: "form-floating"
};
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
  ...{
    inheritAttrs: false
  },
  __name: "BFormGroup",
  props: {
    contentCols: { type: [Boolean, String, Number], default: void 0 },
    labelCols: { type: [Boolean, String, Number], default: void 0 },
    labelAlign: { default: void 0 },
    ariaInvalid: { type: [Boolean, String], default: void 0 },
    description: { default: void 0 },
    disabled: { type: Boolean, default: false },
    feedbackAriaLive: { default: "assertive" },
    floating: { type: Boolean, default: false },
    id: { default: void 0 },
    invalidFeedback: { default: void 0 },
    label: { default: void 0 },
    labelClass: { default: void 0 },
    labelFor: { default: void 0 },
    labelSize: { default: void 0 },
    labelVisuallyHidden: { type: Boolean, default: false },
    state: { type: [Boolean, null], default: null },
    tooltip: { type: Boolean, default: false },
    validFeedback: { default: void 0 },
    validated: { type: Boolean, default: false },
    contentColsSm: { type: [Boolean, String, Number], default: void 0 },
    contentColsMd: { type: [Boolean, String, Number], default: void 0 },
    contentColsLg: { type: [Boolean, String, Number], default: void 0 },
    contentColsXl: { type: [Boolean, String, Number], default: void 0 },
    labelColsSm: { type: [Boolean, String, Number], default: void 0 },
    labelColsMd: { type: [Boolean, String, Number], default: void 0 },
    labelColsLg: { type: [Boolean, String, Number], default: void 0 },
    labelColsXl: { type: [Boolean, String, Number], default: void 0 },
    labelAlignSm: { default: void 0 },
    labelAlignMd: { default: void 0 },
    labelAlignLg: { default: void 0 },
    labelAlignXl: { default: void 0 }
  },
  setup(__props) {
    const INPUTS = ["input", "select", "textarea"];
    const _props = __props;
    const props = useDefaults.useDefaults(_props, "BFormGroup");
    const slots = vue.useSlots();
    const LabelContentTemplate = index.createReusableTemplate();
    const ContentTemplate = index.createReusableTemplate();
    const computedState = vue.toRef(() => props.state);
    const computedDisabled = vue.toRef(() => props.disabled);
    const childId = vue.ref([]);
    vue.provide(keys.formGroupKey, (id) => {
      childId.value = [id];
      return {
        state: computedState,
        disabled: computedDisabled
      };
    });
    const computedLabelFor = vue.computed(() => {
      if (props.labelFor !== void 0) return props.labelFor;
      if (childId.value[0] && childId.value[0].value) return childId.value[0].value;
      return null;
    });
    const breakPoints = ["xs", "sm", "md", "lg", "xl"];
    const getColProps = (props2, prefix) => (
      // eslint-disable-next-line @typescript-eslint/no-explicit-any
      breakPoints.reduce((result, breakpoint) => {
        const suffix = suffixPropName(breakpoint === "xs" ? "" : breakpoint, `${prefix}Cols`);
        let propValue = props2[suffix];
        propValue = propValue === "" ? true : propValue || false;
        if (!(typeof propValue === "boolean") && propValue !== "auto") {
          const val = Number.parseInt(propValue);
          propValue = Number.isNaN(val) ? 0 : val;
          propValue = propValue > 0 ? propValue : false;
        }
        if (propValue) {
          if (breakpoint === "xs") {
            result[typeof propValue === "boolean" ? "col" : "cols"] = propValue;
          } else {
            result[breakpoint || (typeof propValue === "boolean" ? "col" : "cols")] = propValue;
          }
        }
        return result;
      }, {})
    );
    const content = vue.useTemplateRef("_content");
    const contentColProps = vue.computed(() => getColProps(props, "content"));
    const labelAlignClasses = vue.computed(
      () => ((props2, prefix) => breakPoints.reduce((result, breakpoint) => {
        const suffix = suffixPropName(
          breakpoint === "xs" ? "" : breakpoint,
          `${prefix}Align`
        );
        const propValue = props2[suffix] || null;
        if (propValue) {
          if (breakpoint === "xs") {
            result.push(`text-${propValue}`);
          } else {
            result.push(`text-${breakpoint}-${propValue}`);
          }
        }
        return result;
      }, []))(props, "label")
    );
    const labelColProps = vue.computed(() => getColProps(props, "label"));
    const isHorizontal = vue.computed(
      () => Object.keys(contentColProps.value).length > 0 || Object.keys(labelColProps.value).length > 0
    );
    const stateClass = useStateClass.useStateClass(computedState);
    const computedAriaInvalid = useAriaInvalid.useAriaInvalid(() => props.ariaInvalid, computedState);
    const onLegendClick = (event) => {
      if (computedLabelFor.value || content.value === null) return;
      const { target } = event;
      const tagName = target ? target.tagName : "";
      if ([...INPUTS, "a", "button", "label"].indexOf(tagName) !== -1) return;
      const contentElement = isHorizontal.value && content.value && "$el" in content.value ? content.value.$el : content.value;
      if (!contentElement) return;
      const inputs = [
        ...contentElement.querySelectorAll(INPUTS.map((v) => `${v}:not([disabled])`).join())
      ].filter(dom.isVisible);
      const [inp] = inputs;
      if (inputs.length === 1 && inp instanceof HTMLElement) {
        dom.attemptFocus(inp);
      }
    };
    const computedId = useId.useId(() => props.id);
    const labelId = useId.useId(void 0, "_BV_label_");
    const labelTag = vue.computed(() => !computedLabelFor.value ? "legend" : "label");
    const labelClasses = vue.computed(() => [
      isHorizontal.value ? "col-form-label" : "form-label",
      {
        "bv-no-focus-ring": !computedLabelFor.value,
        "col-form-label": isHorizontal.value || !computedLabelFor.value,
        "pt-0": !isHorizontal.value && !computedLabelFor.value,
        "d-block": !isHorizontal.value && computedLabelFor.value,
        [`col-form-label-${props.labelSize}`]: !!props.labelSize,
        "visually-hidden": props.labelVisuallyHidden
      },
      isHorizontal.value ? null : labelAlignClasses.value,
      props.labelClass
    ]);
    const invalidFeedbackId = useId.useId(void 0, "_BV_feedback_invalid_");
    const validFeedbackId = useId.useId(void 0, "_BV_feedback_valid_");
    const descriptionId = useId.useId(void 0, "_BV_description_");
    const isFieldset = vue.computed(() => !computedLabelFor.value);
    return (_ctx, _cache) => {
      return vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(isFieldset.value ? "fieldset" : "div"), vue.mergeProps({
        id: vue.unref(computedId),
        disabled: isFieldset.value ? vue.unref(props).disabled : null,
        role: isFieldset.value ? null : "group",
        "aria-invalid": vue.unref(computedAriaInvalid),
        "aria-labelledby": isFieldset.value && isHorizontal.value ? vue.unref(labelId) : null
      }, _ctx.$attrs, {
        class: [[vue.unref(stateClass), { "was-validated": vue.unref(props).validated }], "b-form-group"]
      }), {
        default: vue.withCtx(() => [
          vue.createVNode(vue.unref(ContentTemplate).define, null, {
            default: vue.withCtx(() => [
              slots["invalid-feedback"] || vue.unref(props).invalidFeedback ? (vue.openBlock(), vue.createBlock(BFormValidFeedback_vue_vue_type_script_setup_true_lang._sfc_main, {
                key: 0,
                id: vue.unref(invalidFeedbackId),
                "aria-live": vue.unref(props).feedbackAriaLive,
                state: computedState.value,
                tooltip: vue.unref(props).tooltip
              }, {
                default: vue.withCtx(() => [
                  vue.renderSlot(_ctx.$slots, "invalid-feedback", {}, () => [
                    vue.createTextVNode(vue.toDisplayString(vue.unref(props).invalidFeedback), 1)
                  ])
                ]),
                _: 3
              }, 8, ["id", "aria-live", "state", "tooltip"])) : vue.createCommentVNode("", true),
              slots["valid-feedback"] || vue.unref(props).validFeedback ? (vue.openBlock(), vue.createBlock(BFormValidFeedback_vue_vue_type_script_setup_true_lang._sfc_main$3, {
                key: 1,
                id: vue.unref(validFeedbackId),
                "aria-live": vue.unref(props).feedbackAriaLive,
                state: computedState.value,
                tooltip: vue.unref(props).tooltip
              }, {
                default: vue.withCtx(() => [
                  vue.renderSlot(_ctx.$slots, "valid-feedback", {}, () => [
                    vue.createTextVNode(vue.toDisplayString(vue.unref(props).validFeedback), 1)
                  ])
                ]),
                _: 3
              }, 8, ["id", "aria-live", "state", "tooltip"])) : vue.createCommentVNode("", true),
              slots.description || vue.unref(props).description ? (vue.openBlock(), vue.createBlock(BFormValidFeedback_vue_vue_type_script_setup_true_lang._sfc_main$2, {
                key: 2,
                id: vue.unref(descriptionId)
              }, {
                default: vue.withCtx(() => [
                  vue.renderSlot(_ctx.$slots, "description", {}, () => [
                    vue.createTextVNode(vue.toDisplayString(vue.unref(props).description), 1)
                  ])
                ]),
                _: 3
              }, 8, ["id"])) : vue.createCommentVNode("", true)
            ]),
            _: 3
          }),
          vue.createVNode(vue.unref(LabelContentTemplate).define, null, {
            default: vue.withCtx(() => [
              slots.label || vue.unref(props).label || isHorizontal.value ? (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 0 }, [
                isHorizontal.value ? (vue.openBlock(), vue.createBlock(BCol_vue_vue_type_script_setup_true_lang._sfc_main, vue.mergeProps({ key: 0 }, labelColProps.value, {
                  id: vue.unref(labelId),
                  tag: labelTag.value,
                  for: computedLabelFor.value || null,
                  tabindex: isFieldset.value ? "-1" : null,
                  class: [labelAlignClasses.value, labelClasses.value],
                  onClick: _cache[0] || (_cache[0] = ($event) => isFieldset.value ? onLegendClick : null)
                }), {
                  default: vue.withCtx(() => [
                    vue.renderSlot(_ctx.$slots, "label", {}, () => [
                      vue.createTextVNode(vue.toDisplayString(vue.unref(props).label), 1)
                    ])
                  ]),
                  _: 3
                }, 16, ["id", "tag", "for", "tabindex", "class"])) : (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(labelTag.value), {
                  key: 1,
                  id: vue.unref(labelId),
                  for: computedLabelFor.value || null,
                  tabindex: isFieldset.value ? "-1" : null,
                  class: vue.normalizeClass(labelClasses.value),
                  onClick: _cache[1] || (_cache[1] = ($event) => isFieldset.value ? onLegendClick : null)
                }, {
                  default: vue.withCtx(() => [
                    vue.renderSlot(_ctx.$slots, "label", {}, () => [
                      vue.createTextVNode(vue.toDisplayString(vue.unref(props).label), 1)
                    ])
                  ]),
                  _: 3
                }, 8, ["id", "for", "tabindex", "class"]))
              ], 64)) : vue.createCommentVNode("", true)
            ]),
            _: 3
          }),
          isHorizontal.value ? (vue.openBlock(), vue.createBlock(BFormValidFeedback_vue_vue_type_script_setup_true_lang._sfc_main$1, { key: 0 }, {
            default: vue.withCtx(() => [
              vue.createVNode(vue.unref(LabelContentTemplate).reuse),
              vue.createVNode(BCol_vue_vue_type_script_setup_true_lang._sfc_main, vue.mergeProps(contentColProps.value, { ref: "_content" }), {
                default: vue.withCtx(() => [
                  vue.renderSlot(_ctx.$slots, "default", {
                    id: vue.unref(computedId),
                    ariaDescribedby: null,
                    descriptionId: vue.unref(descriptionId),
                    labelId: vue.unref(labelId)
                  }),
                  vue.createVNode(vue.unref(ContentTemplate).reuse)
                ]),
                _: 3
              }, 16)
            ]),
            _: 3
          })) : (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 1 }, [
            vue.unref(props).floating && !isHorizontal.value ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_1, [
              vue.renderSlot(_ctx.$slots, "default", {
                id: vue.unref(computedId),
                ariaDescribedby: null,
                descriptionId: vue.unref(descriptionId),
                labelId: vue.unref(labelId)
              }),
              vue.createVNode(vue.unref(LabelContentTemplate).reuse),
              vue.createVNode(vue.unref(ContentTemplate).reuse)
            ], 512)) : (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 1 }, [
              vue.createVNode(vue.unref(LabelContentTemplate).reuse),
              vue.renderSlot(_ctx.$slots, "default", {
                id: vue.unref(computedId),
                ariaDescribedby: null,
                descriptionId: vue.unref(descriptionId),
                labelId: vue.unref(labelId)
              }),
              vue.createVNode(vue.unref(ContentTemplate).reuse)
            ], 64))
          ], 64))
        ]),
        _: 3
      }, 16, ["id", "disabled", "role", "aria-invalid", "aria-labelledby", "class"]);
    };
  }
});
exports._sfc_main = _sfc_main;
//# sourceMappingURL=BFormGroup.vue_vue_type_script_setup_true_lang-7zkXwYPD.js.map
