"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const vue = require("vue");
const keys = require("../../../keys-D70E9HED.js");
const registryAccess = require("../../../registryAccess-DTBpl14X.js");
const useToggle = (id = void 0) => {
  const instance = vue.getCurrentInstance();
  const storage = vue.inject(keys.showHideRegistryKey, null);
  if (!storage) {
    throw new Error(
      "useToggle() must be called within setup(), and BApp, useRegistry or plugin must be installed/provided."
    );
  }
  const registry = storage.values;
  const findComponent = (component) => {
    if (!component.parent) {
      return null;
    }
    if (component.parent.exposed?.["id"] && registry.value.get(vue.toValue(component.parent.exposed.id))) {
      return component.parent;
    }
    return findComponent(component.parent);
  };
  const myComponent = vue.computed(() => {
    const resolvedId = vue.toValue(id);
    if (resolvedId) {
      return registryAccess.getActiveShowHide(registry, resolvedId);
    }
    if (!instance) {
      return null;
    }
    const component = findComponent(instance);
    const componentId = vue.toValue(component?.exposed?.id);
    return registryAccess.getActiveShowHide(registry, componentId);
  });
  return {
    value: vue.computed(() => myComponent.value?.value),
    show: (resolveOnHide) => myComponent.value?.show(resolveOnHide) || Promise.reject("not found"),
    hide: (trigger) => myComponent.value?.hide(trigger, true) || Promise.reject("not found"),
    toggle: (resolveOnHide) => myComponent.value?.toggle(resolveOnHide) || Promise.reject("not found"),
    component: vue.computed(() => myComponent.value?.component)
  };
};
exports.useToggle = useToggle;
//# sourceMappingURL=index.umd.js.map
