import { _ as orchestratorRegistryKey } from "./keys-BgLwJbLV.js";
import { useOrchestratorRegistry } from "./src/composables/orchestratorShared/index.mjs";
import { n as warn } from "./console-DaUCJgpk.js";
import { t as ConditionalTeleport_default } from "./ConditionalTeleport-BCKPLEun.js";
import { useProvideDefaults } from "./src/composables/useProvideDefaults/index.mjs";
import { useRegistry } from "./src/composables/useRegistry/index.mjs";
import { Fragment, TransitionGroup, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createSlots, createVNode, defineComponent, guardReactiveProps, inject, mergeProps, normalizeClass, normalizeProps, normalizeStyle, openBlock, renderList, renderSlot, resolveDynamicComponent, toRef, watch, withCtx } from "vue";
//#endregion
//#region src/components/BApp/BOrchestrator.vue
var BOrchestrator_default = /* @__PURE__ */ 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: void 0
		}
	},
	setup(__props) {
		const setEventOk = (event) => {
			event.ok = event.trigger === "ok" ? true : event.trigger === "cancel" ? false : null;
		};
		const props = __props;
		const orchestratorRegistry = inject(orchestratorRegistryKey, null);
		if (orchestratorRegistry) {
			if (!orchestratorRegistry._isOrchestratorInstalled.value) orchestratorRegistry._setOrchestratorInstalled(true);
		} else warn("BOrchestrator", "The orchestrator registry not found. Please use BApp, useRegistry or provide the plugin.");
		watch(() => props.appendToast, (value) => {
			orchestratorRegistry?._setToastAppend(value);
		}, { immediate: true });
		const items = computed(() => {
			const store = orchestratorRegistry?.store.value;
			let filteredStore = {
				tooltip: !props.noPopovers && store?.tooltip ? [...store.tooltip.values()].map((e) => e.value) : [],
				modal: !props.noModals && store?.modal ? [...store.modal.values()].map((e) => e.value) : [],
				popover: !props.noPopovers && store?.popover ? [...store.popover.values()].map((e) => e.value) : [],
				toast: !props.noToasts && store?.toast ? [...store.toast.values()].map((e) => e.value) : []
			};
			if (props.filter) filteredStore = {
				tooltip: filteredStore.tooltip.filter(props.filter),
				modal: filteredStore.modal.filter(props.filter),
				popover: filteredStore.popover.filter(props.filter),
				toast: filteredStore.toast.filter(props.filter)
			};
			return filteredStore;
		});
		const positionedItems = computed(() => {
			const toastDefaultPosition = "bottom-start";
			const toastDefaults = (cls) => ({
				class: `${cls} toast-container position-fixed p-3`,
				style: "width: calc(var(--bs-toast-max-width, 350px) + var(--bs-toast-padding-x, 1rem) * 2)",
				transitionGroupName: "b-list"
			});
			const allGroups = {
				...items.value.toast.reduce((acc, item) => {
					const pos = item.props.position ?? toastDefaultPosition;
					(acc[pos] ??= {
						...toastDefaults(pos),
						items: []
					}).items.push(item);
					return acc;
				}, {}),
				modal: { items: items.value.modal },
				popover: { items: items.value.popover },
				tooltip: { items: items.value.tooltip }
			};
			return Object.fromEntries(Object.entries(allGroups).filter(([, value]) => value.items.length > 0));
		});
		return (_ctx, _cache) => {
			return openBlock(), createBlock(ConditionalTeleport_default, {
				to: __props.teleportTo,
				disabled: !__props.teleportTo
			}, {
				default: withCtx(() => [createElementVNode("div", mergeProps({ class: "orchestrator-container" }, _ctx.$attrs), [(openBlock(true), createElementBlock(Fragment, null, renderList(positionedItems.value, (value, key) => {
					return openBlock(), createElementBlock("div", {
						key,
						class: normalizeClass(value.class),
						style: normalizeStyle(value.style)
					}, [createVNode(TransitionGroup, { name: value.transitionGroupName }, {
						default: withCtx(() => [(openBlock(true), createElementBlock(Fragment, null, renderList(value.items, ({ component, fns: { setRef, resolve: resolvePromise }, props: componentProps, id, slots, options }) => {
							return openBlock(), createElementBlock("span", { key: id }, [(openBlock(), createBlock(resolveDynamicComponent(component), mergeProps({ ref_for: true }, componentProps, {
								ref_for: true,
								ref: setRef,
								"initial-animation": "",
								"teleport-disabled": true,
								onHide: (e) => {
									setEventOk(e);
									componentProps.onHide?.(e);
									if (e.defaultPrevented) return;
									if (options?.resolveOnHide) resolvePromise(e);
								},
								onHidden: (e) => {
									setEventOk(e);
									componentProps.onHidden?.(e);
									if (e.defaultPrevented) return;
									if (!options?.resolveOnHide) resolvePromise(e);
								}
							}), createSlots({ _: 2 }, [renderList(slots, (comp, slot) => {
								return {
									name: slot,
									fn: withCtx((scope) => [(openBlock(), createBlock(resolveDynamicComponent(comp), mergeProps({ ref_for: true }, scope), null, 16))])
								};
							})]), 1040, ["onHide", "onHidden"]))]);
						}), 128))]),
						_: 2
					}, 1032, ["name"])], 6);
				}), 128))], 16)]),
				_: 1
			}, 8, ["to", "disabled"]);
		};
	}
});
//#endregion
//#region src/components/BApp/BApp.vue
var BApp_default = /* @__PURE__ */ 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;
		useProvideDefaults(toRef(() => props.defaults), props.mergeDefaults);
		useRegistry(props.rtl);
		if (!props.noOrchestrator) useOrchestratorRegistry();
		return (_ctx, _cache) => {
			return openBlock(), createElementBlock(Fragment, null, [!__props.noOrchestrator ? (openBlock(), createBlock(BOrchestrator_default, {
				key: 0,
				"append-toast": __props.appendToast,
				"teleport-to": __props.teleportTo
			}, null, 8, ["append-toast", "teleport-to"])) : createCommentVNode("", true), renderSlot(_ctx.$slots, "default", normalizeProps(guardReactiveProps(_ctx.$attrs)))], 64);
		};
	}
});
//#endregion
export { BOrchestrator_default as n, BApp_default as t };

//# sourceMappingURL=BApp-GXR1wS6K.js.map