"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const vue = require("vue");
const keys = require("../../../keys-D70E9HED.js");
const src_composables_orchestratorShared_index = require("../orchestratorShared/index.umd.js");
require("../../../BootstrapVueOptions-B17IcLXU.js");
require("../../../ConditionalTeleport.vue_vue_type_script_lang-BL9AAILt.js");
require("../../../ConditionalWrapper.vue_vue_type_script_lang-CFfEbslT.js");
require("../../../useTransitions-C9Xv-y_E.js");
require("../../../tableUtils-MbGcRaD0.js");
const BToast_vue_vue_type_script_setup_true_lang = require("../../../BToast.vue_vue_type_script_setup_true_lang-4HSanqr6.js");
const posDefault = "top-end";
const useToast = () => {
  const orchestratorRegistry = vue.inject(keys.orchestratorRegistryKey, null);
  if (!orchestratorRegistry) {
    throw new Error(
      "useToast() must be called within setup(), and BApp, useRegistry or plugin must be installed/provided."
    );
  }
  const { store, _isToastAppend, _isOrchestratorInstalled } = orchestratorRegistry;
  const create = (obj = {}, options = {}) => {
    if (!_isOrchestratorInstalled.value) {
      throw new Error("The BApp component must be mounted to use the toast composable");
    }
    const resolvedProps = vue.isRef(obj) ? obj : vue.shallowRef(obj);
    const _self = resolvedProps.value?.id || /* @__PURE__ */ Symbol("Toast controller");
    const promise = src_composables_orchestratorShared_index.buildPromise(_self, store);
    promise.stop = vue.watch(
      resolvedProps,
      (_newValue) => {
        const newValue = { ...vue.toValue(_newValue) };
        const previousIndex = store.value.findIndex((el) => el._self === _self);
        const previous = previousIndex === -1 ? { _component: vue.markRaw(BToast_vue_vue_type_script_setup_true_lang._sfc_main) } : store.value[previousIndex];
        const v = {
          ...previous,
          type: "toast",
          _self,
          promise,
          options
        };
        if (newValue.props) {
          Object.assign(v, newValue.props);
          newValue.props = void 0;
        }
        if (newValue.pos) {
          v.position = newValue.pos;
          newValue.pos = void 0;
        }
        for (const key in newValue) {
          if (key.startsWith("on")) {
            v[key] = newValue[key];
          } else if (key === "component" && newValue.component) {
            v._component = vue.markRaw(newValue.component);
          } else if (key === "slots" && newValue.slots) {
            v.slots = vue.markRaw(newValue.slots);
          } else {
            v[key] = vue.toValue(
              newValue[key]
            );
          }
        }
        v.position = v.position || posDefault;
        v.modelValue = v.modelValue ?? 5e3;
        v["onUpdate:modelValue"] = (val) => {
          newValue["onUpdate:modelValue"]?.(val);
          const { modelValue } = vue.toValue(obj);
          if (vue.isRef(obj) && !vue.isRef(modelValue)) obj.value.modelValue = val;
          if (vue.isRef(modelValue) && !vue.isReadonly(modelValue)) {
            modelValue.value = val;
          }
          if (v.modelValue !== val) {
            const toast = store.value.find((el) => el._self === _self);
            if (toast) {
              toast.modelValue = val;
            }
          }
        };
        if (previousIndex === -1) {
          if (resolvedProps.value?.appendToast !== void 0 ? resolvedProps.value.appendToast : _isToastAppend.value) {
            store.value.push(v);
          } else {
            store.value.unshift(v);
          }
        } else {
          store.value.splice(previousIndex, 1, v);
        }
      },
      {
        deep: true,
        immediate: true
      }
    );
    vue.onScopeDispose(() => {
      const toast = store.value.find((el) => el._self === _self);
      if (toast) {
        toast.promise.value.destroy?.();
      }
    }, true);
    return promise.value;
  };
  const show = (obj = {}) => {
    console.warn(
      "[BootstrapVueNext] useToast: The `show` method is deprecated. Use the `create` method instead."
    );
    return create(obj);
  };
  return {
    _isToastAppend,
    _isOrchestratorInstalled,
    store,
    create,
    show
  };
};
const useToastController = useToast;
exports.useToast = useToast;
exports.useToastController = useToastController;
//# sourceMappingURL=index.umd.js.map
