"use strict";
const BButton_vue_vue_type_script_setup_true_lang = require("./BButton.vue_vue_type_script_setup_true_lang-CXQy0Rf_.js");
const vue = require("vue");
const BLink_vue_vue_type_script_setup_true_lang = require("./BLink.vue_vue_type_script_setup_true_lang-B4Fy2Ncx.js");
const BCloseButton_vue_vue_type_script_setup_true_lang = require("./BCloseButton.vue_vue_type_script_setup_true_lang-CbUMoMu7.js");
const BProgress_vue_vue_type_script_setup_true_lang = require("./BProgress.vue_vue_type_script_setup_true_lang-By-yrDYc.js");
const useCountdownHover = require("./useCountdownHover-sffPPwQG.js");
const useColorVariantClasses = require("./useColorVariantClasses-BjkZZDqD.js");
const useDefaults = require("./useDefaults-YXpmugKp.js");
const useId = require("./useId-Dl8Hi5_U.js");
const useShowHide = require("./useShowHide-b1MKf6Ye.js");
const _hoisted_1 = ["id", "role", "aria-live", "aria-atomic"];
const _hoisted_2 = {
  key: 1,
  class: "d-flex"
};
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
  __name: "BToast",
  props: /* @__PURE__ */ vue.mergeModels({
    body: { default: void 0 },
    bodyClass: { default: void 0 },
    closeClass: { default: void 0 },
    closeContent: { default: void 0 },
    closeLabel: { default: "Close" },
    closeVariant: { default: "secondary" },
    headerClass: { default: void 0 },
    headerTag: { default: "div" },
    id: { default: void 0 },
    interval: { default: "requestAnimationFrame" },
    isStatus: { type: Boolean, default: false },
    noCloseButton: { type: Boolean, default: false },
    noHoverPause: { type: Boolean, default: false },
    noProgress: { type: Boolean, default: false },
    noResumeOnHoverLeave: { type: Boolean, default: false },
    progressProps: { default: void 0 },
    showOnPause: { type: Boolean, default: true },
    solid: { type: Boolean, default: false },
    title: { default: void 0 },
    toastClass: { default: void 0 },
    variant: { default: void 0 },
    bgVariant: { default: null },
    textVariant: { default: null },
    active: { type: Boolean, default: void 0 },
    activeClass: { default: void 0 },
    disabled: { type: Boolean, default: void 0 },
    exactActiveClass: { default: void 0 },
    href: { default: void 0 },
    icon: { type: Boolean, default: void 0 },
    noRel: { type: Boolean, default: void 0 },
    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 },
    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: void 0 },
    initialAnimation: { type: Boolean, default: false },
    noAnimation: { type: Boolean },
    noFade: { type: Boolean, default: false },
    lazy: { type: Boolean, default: false },
    unmountLazy: { type: Boolean, default: false },
    show: { type: Boolean, default: false },
    transProps: { default: void 0 },
    visible: { type: Boolean, default: false }
  }, {
    "modelValue": { type: [Boolean, Number], ...{ default: false } },
    "modelModifiers": {}
  }),
  emits: /* @__PURE__ */ vue.mergeModels(["close", "close-countdown", "hide", "hide-prevented", "hidden", "show", "show-prevented", "shown", "toggle", "toggle-prevented"], ["update:modelValue"]),
  setup(__props, { expose: __expose, emit: __emit }) {
    const _props = __props;
    const props = useDefaults.useDefaults(_props, "BToast");
    const emit = __emit;
    const slots = vue.useSlots();
    const element = vue.useTemplateRef("_element");
    const modelValue = vue.useModel(__props, "modelValue");
    const { computedLink, computedLinkProps } = BLink_vue_vue_type_script_setup_true_lang.useBLinkHelper(props);
    const computedId = useId.useId(() => props.id, "toast");
    const {
      showRef,
      renderRef,
      hide,
      toggle,
      show,
      buildTriggerableEvent,
      computedNoAnimation,
      isVisible,
      transitionProps,
      contentShowing
    } = useShowHide.useShowHide(modelValue, props, emit, element, computedId);
    const countdownLength = vue.computed(
      () => typeof modelValue.value === "boolean" ? 0 : modelValue.value
    );
    const {
      isActive,
      pause,
      restart,
      resume,
      stop,
      isPaused,
      value: remainingMs
    } = useCountdownHover.useCountdown(countdownLength, props.interval, {
      immediate: typeof modelValue.value === "number" && !!modelValue.value
    });
    useCountdownHover.useCountdownHover(
      element,
      {
        noHoverPause: () => props.noHoverPause || typeof modelValue.value !== "number",
        noResumeOnHoverLeave: () => props.noResumeOnHoverLeave || typeof modelValue.value !== "number",
        modelValueIgnoresHover: () => typeof modelValue.value === "boolean"
      },
      { pause, resume }
    );
    vue.watchEffect(() => {
      emit("close-countdown", remainingMs.value);
    });
    const computedTag = vue.computed(() => computedLink.value ? BLink_vue_vue_type_script_setup_true_lang._sfc_main : "div");
    const isToastVisible = vue.computed(
      () => showRef.value || isActive.value || props.showOnPause && isPaused.value
    );
    const colorClasses = useColorVariantClasses.useColorVariantClasses(props);
    const computedClasses = vue.computed(() => [
      colorClasses.value,
      {
        show: isVisible.value,
        fade: !computedNoAnimation.value
      }
    ]);
    vue.watch(modelValue, (newValue, oldValue) => {
      if (typeof newValue === "number" && newValue > 0) {
        const event = buildTriggerableEvent("show", { cancelable: true, trigger: "model" });
        emit("show", event);
        if (event.defaultPrevented) {
          emit("show-prevented", buildTriggerableEvent("show-prevented"));
        } else {
          restart();
        }
      }
      if (typeof newValue === "number" && newValue === 0) {
        stop();
      }
      if (newValue === false && typeof oldValue === "number" && oldValue > 0) {
        stop();
      }
    });
    vue.watch(isActive, (newValue) => {
      if (newValue === false && isPaused.value === false) {
        hide();
        modelValue.value = 0;
        stop();
      }
    });
    const sharedSlots = vue.computed(() => ({
      toggle,
      show,
      hide,
      id: computedId.value,
      visible: showRef.value,
      active: isActive.value
    }));
    __expose({
      show,
      hide,
      toggle,
      pause,
      restart,
      resume,
      stop
    });
    return (_ctx, _cache) => {
      const _component_BButton = BButton_vue_vue_type_script_setup_true_lang._sfc_main;
      return vue.unref(renderRef) || vue.unref(contentShowing) ? (vue.openBlock(), vue.createBlock(vue.Transition, vue.mergeProps({ key: 0 }, vue.unref(transitionProps), {
        appear: !!modelValue.value || vue.unref(props).visible
      }), {
        default: vue.withCtx(() => [
          vue.withDirectives(vue.createElementVNode("div", {
            id: vue.unref(props).id,
            ref: "_element",
            class: vue.normalizeClass(["toast", [vue.unref(props).toastClass, computedClasses.value]]),
            tabindex: "0",
            style: { "display": "block" },
            role: !isToastVisible.value ? void 0 : vue.unref(props).isStatus ? "status" : "alert",
            "aria-live": !isToastVisible.value ? void 0 : vue.unref(props).isStatus ? "polite" : "assertive",
            "aria-atomic": !isToastVisible.value ? void 0 : true
          }, [
            vue.unref(contentShowing) && (slots.title || vue.unref(props).title) ? (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(vue.unref(props).headerTag), {
              key: 0,
              class: vue.normalizeClass(["toast-header", vue.unref(props).headerClass])
            }, {
              default: vue.withCtx(() => [
                vue.renderSlot(_ctx.$slots, "title", vue.normalizeProps(vue.guardReactiveProps(sharedSlots.value)), () => [
                  vue.createElementVNode("strong", null, vue.toDisplayString(vue.unref(props).title), 1)
                ]),
                !vue.unref(props).noCloseButton ? (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 0 }, [
                  slots.close || vue.unref(props).closeContent ? (vue.openBlock(), vue.createBlock(_component_BButton, {
                    key: 0,
                    class: vue.normalizeClass([[vue.unref(props).closeClass], "ms-auto"]),
                    variant: vue.unref(props).closeVariant,
                    onClick: _cache[0] || (_cache[0] = vue.withModifiers(($event) => vue.unref(hide)("close"), ["stop", "prevent"]))
                  }, {
                    default: vue.withCtx(() => [
                      vue.renderSlot(_ctx.$slots, "close", vue.normalizeProps(vue.guardReactiveProps(sharedSlots.value)), () => [
                        vue.createTextVNode(vue.toDisplayString(vue.unref(props).closeContent), 1)
                      ])
                    ]),
                    _: 3
                  }, 8, ["class", "variant"])) : (vue.openBlock(), vue.createBlock(BCloseButton_vue_vue_type_script_setup_true_lang._sfc_main, {
                    key: 1,
                    "aria-label": vue.unref(props).closeLabel,
                    class: vue.normalizeClass(["ms-auto", [vue.unref(props).closeClass]]),
                    onClick: _cache[1] || (_cache[1] = vue.withModifiers(($event) => vue.unref(hide)("close"), ["stop", "prevent"]))
                  }, null, 8, ["aria-label", "class"]))
                ], 64)) : vue.createCommentVNode("", true)
              ]),
              _: 3
            }, 8, ["class"])) : vue.createCommentVNode("", true),
            vue.unref(contentShowing) && (slots.default || vue.unref(props).body) ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_2, [
              (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(computedTag.value), vue.mergeProps({
                class: ["toast-body", vue.unref(props).bodyClass]
              }, vue.unref(computedLinkProps), {
                onClick: _cache[2] || (_cache[2] = ($event) => vue.unref(computedLink) ? vue.unref(hide)() : () => {
                })
              }), {
                default: vue.withCtx(() => [
                  vue.renderSlot(_ctx.$slots, "default", vue.normalizeProps(vue.guardReactiveProps(sharedSlots.value)), () => [
                    vue.createTextVNode(vue.toDisplayString(vue.unref(props).body), 1)
                  ])
                ]),
                _: 3
              }, 16, ["class"])),
              !vue.unref(props).noCloseButton && !(slots.title || vue.unref(props).title) ? (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 0 }, [
                slots.close || vue.unref(props).closeContent ? (vue.openBlock(), vue.createBlock(_component_BButton, {
                  key: 0,
                  class: vue.normalizeClass([[vue.unref(props).closeClass], "ms-auto btn-close-custom"]),
                  variant: vue.unref(props).closeVariant,
                  onClick: _cache[3] || (_cache[3] = vue.withModifiers(($event) => vue.unref(hide)("close"), ["stop", "prevent"]))
                }, {
                  default: vue.withCtx(() => [
                    vue.renderSlot(_ctx.$slots, "close", vue.normalizeProps(vue.guardReactiveProps(sharedSlots.value)), () => [
                      vue.createTextVNode(vue.toDisplayString(vue.unref(props).closeContent), 1)
                    ])
                  ]),
                  _: 3
                }, 8, ["class", "variant"])) : (vue.openBlock(), vue.createBlock(BCloseButton_vue_vue_type_script_setup_true_lang._sfc_main, {
                  key: 1,
                  "aria-label": vue.unref(props).closeLabel,
                  class: vue.normalizeClass(["ms-auto btn-close-custom", [vue.unref(props).closeClass]]),
                  onClick: _cache[4] || (_cache[4] = vue.withModifiers(($event) => vue.unref(hide)("close"), ["stop", "prevent"]))
                }, null, 8, ["aria-label", "class"]))
              ], 64)) : vue.createCommentVNode("", true)
            ])) : vue.createCommentVNode("", true),
            typeof modelValue.value === "number" && !vue.unref(props).noProgress ? (vue.openBlock(), vue.createBlock(BProgress_vue_vue_type_script_setup_true_lang._sfc_main, {
              key: 2,
              animated: vue.unref(props).progressProps?.animated,
              precision: vue.unref(props).progressProps?.precision,
              "show-progress": vue.unref(props).progressProps?.showProgress,
              "show-value": vue.unref(props).progressProps?.showValue,
              striped: vue.unref(props).progressProps?.striped,
              variant: vue.unref(props).progressProps?.variant,
              max: modelValue.value,
              value: vue.unref(remainingMs),
              height: "4px"
            }, null, 8, ["animated", "precision", "show-progress", "show-value", "striped", "variant", "max", "value"])) : vue.createCommentVNode("", true)
          ], 10, _hoisted_1), [
            [vue.vShow, isToastVisible.value]
          ])
        ]),
        _: 3
      }, 16, ["appear"])) : vue.createCommentVNode("", true);
    };
  }
});
exports._sfc_main = _sfc_main;
//# sourceMappingURL=BToast.vue_vue_type_script_setup_true_lang-4HSanqr6.js.map
