"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const vue = require("vue");
const keys = require("../../../keys-D70E9HED.js");
const useRegistry = (rtl = false) => {
  const showHideStorage = vue.inject(keys.showHideRegistryKey, null);
  if (!showHideStorage) {
    const { register, values } = _newShowHideRegistry();
    vue.provide(keys.showHideRegistryKey, { register, values });
  }
  const modalManager = vue.inject(keys.modalManagerKey, null);
  if (!modalManager) {
    const stack = vue.ref(/* @__PURE__ */ new Map());
    const countStack = vue.computed(() => stack.value.size);
    const valuesStack = vue.computed(() => [...stack.value.values()]);
    const lastStack = vue.computed(() => valuesStack.value[valuesStack.value.length - 1]);
    const pushStack = (modal) => {
      stack.value.set(modal.uid, modal);
    };
    const removeStack = (modal) => {
      stack.value.delete(modal.uid);
    };
    const registry = vue.ref(/* @__PURE__ */ new Map());
    const pushRegistry = (modal) => {
      registry.value.set(modal.uid, modal);
    };
    const removeRegistry = (modal) => {
      registry.value.delete(modal.uid);
    };
    vue.provide(keys.modalManagerKey, {
      countStack,
      lastStack,
      registry: vue.computed(() => registry.value),
      stack: valuesStack,
      pushStack,
      removeStack,
      pushRegistry,
      removeRegistry
    });
  }
  const breadcrumb = vue.inject(keys.breadcrumbRegistryKey, null);
  if (!breadcrumb) {
    const items = vue.ref({
      [keys.breadcrumbGlobalIndexKey]: []
    });
    const reset = (key = keys.breadcrumbGlobalIndexKey) => {
      items.value[key] = [];
    };
    vue.provide(keys.breadcrumbRegistryKey, { items, reset });
  }
  const rtlRegistry = vue.inject(keys.rtlRegistryKey, null);
  if (!rtlRegistry) {
    const rtlDefault = false;
    const localeDefault = void 0;
    const rtlInitial = typeof rtl === "boolean" ? rtlDefault : rtl?.rtlInitial ?? rtlDefault;
    const localeInitial = typeof rtl === "boolean" ? localeDefault : rtl?.localeInitial ?? localeDefault;
    const isRtl = vue.ref(rtlInitial);
    const locale = vue.ref(localeInitial);
    vue.provide(keys.rtlRegistryKey, { isRtl, locale });
  }
};
const createGetActive = (instances) => () => instances.length > 0 ? instances[instances.length - 1] : void 0;
const _newShowHideRegistry = () => {
  const values = vue.ref(/* @__PURE__ */ new Map());
  const register = ({
    id,
    component,
    value,
    toggle,
    show,
    hide,
    registerTrigger,
    unregisterTrigger
  }) => {
    let currentId = id;
    const instanceValue = {
      id,
      component,
      value: vue.readonly(value),
      toggle,
      show,
      hide,
      registerTrigger,
      unregisterTrigger
    };
    let instancesHolder = values.value.get(currentId);
    if (!instancesHolder) {
      const instances = [];
      instancesHolder = {
        instances,
        // Returns the last mounted instance (most recent)
        getActive: createGetActive(instances)
      };
      values.value.set(currentId, instancesHolder);
    }
    instancesHolder.instances.push(instanceValue);
    const componentUid = component.uid;
    return {
      unregister() {
        const holder = values.value.get(currentId);
        if (!holder) return;
        const index = holder.instances.findIndex(
          (inst) => inst.component.uid === componentUid
        );
        if (index !== -1) {
          holder.instances.splice(index, 1);
        }
        if (holder.instances.length === 0) {
          values.value.delete(currentId);
        }
      },
      updateId(newId, oldId) {
        const holder = values.value.get(oldId);
        if (!holder) return;
        const instance = holder.instances.find(
          (inst) => inst.component.uid === componentUid
        );
        if (!instance) return;
        instance.id = newId;
        let newHolder = values.value.get(newId);
        if (!newHolder) {
          const instances = [];
          newHolder = {
            instances,
            getActive: createGetActive(instances)
          };
          values.value.set(newId, newHolder);
        }
        const index = holder.instances.findIndex(
          (inst) => inst.component.uid === componentUid
        );
        if (index !== -1) {
          holder.instances.splice(index, 1);
          newHolder.instances.push(instance);
        }
        if (holder.instances.length === 0) {
          values.value.delete(oldId);
        }
        currentId = newId;
      }
    };
  };
  return {
    register,
    values
  };
};
exports._newShowHideRegistry = _newShowHideRegistry;
exports.useRegistry = useRegistry;
//# sourceMappingURL=index.umd.js.map
