"use strict";
const vue = require("vue");
const keys = require("./keys-D70E9HED.js");
const ConditionalTeleport_vue_vue_type_script_lang = require("./ConditionalTeleport.vue_vue_type_script_lang-BL9AAILt.js");
const src_composables_useProvideDefaults_index = require("./src/composables/useProvideDefaults/index.umd.js");
const src_composables_useRegistry_index = require("./src/composables/useRegistry/index.umd.js");
const src_composables_orchestratorShared_index = require("./src/composables/orchestratorShared/index.umd.js");
const positionClasses = {
  "top-start": "top-0 start-0",
  "top-center": "top-0 start-50 translate-middle-x",
  "top-end": "top-0 end-0",
  "middle-start": "top-50 start-0 translate-middle-y",
  "middle-center": "top-50 start-50 translate-middle",
  "middle-end": "top-50 end-0 translate-middle-y",
  "bottom-start": "bottom-0 start-0",
  "bottom-center": "bottom-0 start-50 translate-middle-x",
  "bottom-end": "bottom-0 end-0"
};
const _sfc_main$1 = /* @__PURE__ */ vue.defineComponent({
  __name: "BOrchestrator",
  props: {
    noPopovers: { type: Boolean, default: false },
    noToasts: { type: Boolean, default: false },
    noModals: { type: Boolean, default: false },
    appendToast: { type: Boolean, default: false },
    teleportTo: {},
    filter: { type: Function, default: () => true }
  },
  setup(__props) {
    function setEventOk(event) {
      event.ok = event.trigger === "ok" ? true : event.trigger === "cancel" ? false : null;
    }
    const props = __props;
    const orchestratorRegistry = vue.inject(keys.orchestratorRegistryKey, null);
    if (orchestratorRegistry) {
      if (!orchestratorRegistry._isOrchestratorInstalled.value) {
        orchestratorRegistry._isOrchestratorInstalled.value = true;
      }
    } else {
      if (process.env.NODE_ENV === "development") {
        console.warn(
          "[BOrchestrator] The orchestrator registry not found. Please use BApp, useRegistry or provide the plugin."
        );
      }
    }
    vue.watch(
      () => props.appendToast,
      (value) => {
        if (orchestratorRegistry && value !== void 0) {
          orchestratorRegistry._isToastAppend.value = value;
        }
      },
      { immediate: true }
    );
    const ComputedPositionClasses = vue.computed(() => {
      const positionsActive = items.value?.reduce(
        (acc, item) => {
          if (item.position) {
            acc[item.position] = true;
          }
          return acc;
        },
        {}
      );
      const classes = {};
      for (const position in positionClasses) {
        if (positionsActive?.[position]) {
          classes[position] = {
            class: `${positionClasses[position]} toast-container position-fixed p-3`,
            style: "width: calc(var(--bs-toast-max-width, 350px) + var(--bs-toast-padding-x, 1rem) * 2)"
          };
        }
      }
      if (positionsActive?.["modal"]) {
        classes["modal"] = {
          class: "",
          style: ""
        };
      }
      if (positionsActive?.["popover"]) {
        classes["popover"] = {
          class: "",
          style: ""
        };
      }
      return classes;
    });
    const items = vue.computed(() => {
      const store = orchestratorRegistry?.store.value ?? [];
      return store.filter((el) => !props.noPopovers || el.type !== "popover").filter((el) => !props.noToasts || el.type !== "toast").filter((el) => !props.noModals || el.type !== "modal").filter(props.filter);
    });
    return (_ctx, _cache) => {
      return vue.openBlock(), vue.createBlock(ConditionalTeleport_vue_vue_type_script_lang._sfc_main, {
        to: __props.teleportTo,
        disabled: !__props.teleportTo
      }, {
        default: vue.withCtx(() => [
          vue.createElementVNode("div", vue.mergeProps({ class: "orchestrator-container" }, _ctx.$attrs), [
            (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(ComputedPositionClasses.value, (value, key) => {
              return vue.openBlock(), vue.createElementBlock("div", {
                key,
                class: vue.normalizeClass(value.class),
                style: vue.normalizeStyle(value.style)
              }, [
                vue.createVNode(vue.TransitionGroup, {
                  name: items.value?.filter((el) => el.position === key)?.some((el) => el.type === "toast") ? "b-list" : void 0
                }, {
                  default: vue.withCtx(() => [
                    (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(items.value?.filter((el) => el.position === key) || [], ({
                      _self,
                      type,
                      position,
                      slots,
                      promise,
                      options,
                      _component,
                      ...val
                    }) => {
                      return vue.openBlock(), vue.createElementBlock("span", { key: _self }, [
                        (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(_component), vue.mergeProps({ ref_for: true }, val, {
                          ref_for: true,
                          ref: (ref) => promise.value.ref = ref,
                          "initial-animation": "",
                          "teleport-disabled": true,
                          onHide: (e) => {
                            setEventOk(e);
                            val.onHide?.(e);
                            if (e.defaultPrevented) {
                              return;
                            }
                            promise.stop?.();
                            if (options?.resolveOnHide) {
                              promise.resolve(e);
                            }
                          },
                          onHidden: (e) => {
                            setEventOk(e);
                            val.onHidden?.(e);
                            if (e.defaultPrevented) {
                              return;
                            }
                            if (!options?.resolveOnHide) {
                              promise.resolve(e);
                            }
                            if (!options?.keep) {
                              promise.value.destroy?.();
                            }
                          }
                        }), vue.createSlots({ _: 2 }, [
                          vue.renderList(slots, (comp, slot) => {
                            return {
                              name: slot,
                              fn: vue.withCtx((scope) => [
                                (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(comp), vue.mergeProps({ ref_for: true }, scope), null, 16))
                              ])
                            };
                          })
                        ]), 1040, ["onHide", "onHidden"]))
                      ]);
                    }), 128))
                  ]),
                  _: 2
                }, 1032, ["name"])
              ], 6);
            }), 128))
          ], 16)
        ]),
        _: 1
      }, 8, ["to", "disabled"]);
    };
  }
});
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
  ...{
    inheritAttrs: false
  },
  __name: "BApp",
  props: {
    defaults: { default: void 0 },
    mergeDefaults: { type: [Boolean, Function], default: false },
    teleportTo: { default: void 0 },
    noOrchestrator: { type: Boolean, default: false },
    appendToast: { type: Boolean, default: false },
    rtl: { type: [Boolean, Object], default: false }
  },
  setup(__props) {
    const props = __props;
    src_composables_useProvideDefaults_index.useProvideDefaults(
      vue.toRef(() => props.defaults),
      props.mergeDefaults
    );
    src_composables_useRegistry_index.useRegistry(props.rtl);
    if (!props.noOrchestrator) {
      src_composables_orchestratorShared_index.useOrchestratorRegistry();
    }
    return (_ctx, _cache) => {
      return vue.openBlock(), vue.createElementBlock(vue.Fragment, null, [
        !__props.noOrchestrator ? (vue.openBlock(), vue.createBlock(_sfc_main$1, {
          key: 0,
          "append-toast": __props.appendToast,
          "teleport-to": __props.teleportTo
        }, null, 8, ["append-toast", "teleport-to"])) : vue.createCommentVNode("", true),
        vue.renderSlot(_ctx.$slots, "default", vue.normalizeProps(vue.guardReactiveProps(_ctx.$attrs)))
      ], 64);
    };
  }
});
exports._sfc_main = _sfc_main;
exports._sfc_main$1 = _sfc_main$1;
//# sourceMappingURL=BApp.vue_vue_type_script_setup_true_lang-BooFFY0h.js.map
