"use strict";
const vue = require("vue");
const BSpinner_vue_vue_type_script_setup_true_lang = require("./BSpinner.vue_vue_type_script_setup_true_lang-CKRhsbDa.js");
const BLink_vue_vue_type_script_setup_true_lang = require("./BLink.vue_vue_type_script_setup_true_lang-B4Fy2Ncx.js");
const index = require("./index-C_bsiScj.js");
const useDefaults = require("./useDefaults-YXpmugKp.js");
require("./BootstrapVueOptions-B17IcLXU.js");
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
  __name: "BButton",
  props: /* @__PURE__ */ vue.mergeModels({
    loading: { type: Boolean, default: false },
    loadingFill: { type: Boolean, default: false },
    loadingText: { default: "Loading..." },
    pill: { type: Boolean, default: false },
    size: { default: "md" },
    squared: { type: Boolean, default: false },
    tag: { default: "button" },
    type: { default: "button" },
    variant: { default: "secondary" },
    active: { type: Boolean, default: false },
    activeClass: { default: void 0 },
    disabled: { type: Boolean, default: void 0 },
    exactActiveClass: { default: void 0 },
    href: { default: void 0 },
    icon: { type: Boolean, default: false },
    noRel: { type: Boolean },
    opacity: { default: void 0 },
    opacityHover: { default: void 0 },
    prefetch: { type: Boolean },
    prefetchOn: {},
    noPrefetch: { type: Boolean },
    prefetchedClass: {},
    rel: { default: void 0 },
    replace: { type: Boolean, default: void 0 },
    routerComponentName: { default: void 0 },
    routerTag: { default: void 0 },
    stretched: { type: Boolean, default: false },
    target: { default: void 0 },
    to: { default: void 0 },
    underlineOffset: { default: void 0 },
    underlineOffsetHover: { default: void 0 },
    underlineOpacity: { default: void 0 },
    underlineOpacityHover: { default: void 0 },
    underlineVariant: { default: null }
  }, {
    "pressed": { type: Boolean, ...{ default: void 0 } },
    "pressedModifiers": {}
  }),
  emits: /* @__PURE__ */ vue.mergeModels(["click"], ["update:pressed"]),
  setup(__props, { emit: __emit }) {
    const _props = __props;
    const props = useDefaults.useDefaults(_props, "BButton");
    const emit = __emit;
    const element = vue.useTemplateRef("_element");
    const pressedValue = vue.useModel(__props, "pressed");
    const { computedLink, computedLinkProps } = BLink_vue_vue_type_script_setup_true_lang.useBLinkHelper(props, [
      "activeClass",
      "exactActiveClass",
      "replace",
      "routerComponentName",
      "routerTag",
      "noPrefetch",
      "prefetch",
      "prefetchOn",
      "prefetchedClass"
    ]);
    const isToggle = vue.computed(() => typeof pressedValue.value === "boolean");
    const isButton = vue.computed(
      () => props.tag === "button" && props.href === void 0 && props.to === void 0
    );
    const isBLink = vue.computed(() => props.to !== void 0);
    const nonStandardTag = vue.computed(() => props.href !== void 0 ? false : !isButton.value);
    const linkProps = vue.computed(() => isBLink.value ? computedLinkProps.value : []);
    const computedAriaDisabled = vue.computed(() => {
      if (props.href === "#" && props.disabled) return true;
      return nonStandardTag.value ? props.disabled : null;
    });
    const variantIsLinkType = vue.computed(() => props.variant?.startsWith("link") || false);
    const variantIsLinkTypeSubset = vue.computed(() => props.variant?.startsWith("link-") || false);
    const linkValueClasses = BLink_vue_vue_type_script_setup_true_lang.useLinkClasses(
      vue.computed(() => ({
        ...variantIsLinkType.value ? {
          icon: props.icon,
          opacity: props.opacity,
          opacityHover: props.opacityHover,
          underlineOffset: props.underlineOffset,
          underlineOffsetHover: props.underlineOffsetHover,
          underlineOpacity: props.underlineOpacity,
          underlineOpacityHover: props.underlineOpacityHover,
          underlineVariant: props.underlineVariant,
          variant: variantIsLinkTypeSubset.value === true ? props.variant?.slice(5) : null
        } : void 0
      }))
    );
    const computedClasses = vue.computed(() => [
      variantIsLinkType.value === true && computedLink.value === false ? linkValueClasses.value : void 0,
      [`btn-${props.size}`],
      {
        [`btn-${props.variant}`]: props.variant !== null && variantIsLinkTypeSubset.value === false,
        "active": props.active || pressedValue.value,
        "rounded-pill": props.pill,
        "rounded-0": props.squared,
        "disabled": props.disabled
      }
    ]);
    const computedTag = vue.computed(() => isBLink.value ? BLink_vue_vue_type_script_setup_true_lang._sfc_main : props.href ? "a" : props.tag);
    const clicked = (e) => {
      if (props.disabled) {
        e.preventDefault();
        e.stopPropagation();
        return;
      }
      emit("click", e);
      if (isToggle.value) pressedValue.value = !pressedValue.value;
    };
    index.onKeyStroke(
      [" ", "enter"],
      (e) => {
        if (props.href === "#") {
          e.preventDefault();
          element.value?.click();
        }
      },
      { target: element }
    );
    return (_ctx, _cache) => {
      return vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(computedTag.value), vue.mergeProps({
        ref: "_element",
        class: "btn"
      }, linkProps.value, {
        class: computedClasses.value,
        "aria-disabled": computedAriaDisabled.value,
        "aria-pressed": isToggle.value ? pressedValue.value : null,
        autocomplete: isToggle.value ? "off" : null,
        disabled: isButton.value ? vue.unref(props).disabled : null,
        href: vue.unref(props).href,
        rel: vue.unref(computedLink) ? vue.unref(props).rel : null,
        role: nonStandardTag.value || vue.unref(computedLink) ? "button" : null,
        target: vue.unref(computedLink) ? vue.unref(props).target : null,
        type: isButton.value ? vue.unref(props).type : null,
        to: !isButton.value ? vue.unref(props).to : null,
        onClick: clicked
      }), {
        default: vue.withCtx(() => [
          vue.unref(props).loading ? vue.renderSlot(_ctx.$slots, "loading", { key: 0 }, () => [
            !vue.unref(props).loadingFill ? (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 0 }, [
              vue.createTextVNode(vue.toDisplayString(vue.unref(props).loadingText), 1)
            ], 64)) : vue.createCommentVNode("", true),
            vue.renderSlot(_ctx.$slots, "loading-spinner", {}, () => [
              vue.createVNode(BSpinner_vue_vue_type_script_setup_true_lang._sfc_main, {
                small: vue.unref(props).size !== "lg",
                label: vue.unref(props).loadingFill ? vue.unref(props).loadingText : void 0
              }, null, 8, ["small", "label"])
            ])
          ]) : vue.renderSlot(_ctx.$slots, "default", { key: 1 })
        ]),
        _: 3
      }, 16, ["class", "aria-disabled", "aria-pressed", "autocomplete", "disabled", "href", "rel", "role", "target", "type", "to"]);
    };
  }
});
exports._sfc_main = _sfc_main;
//# sourceMappingURL=BButton.vue_vue_type_script_setup_true_lang-CXQy0Rf_.js.map
