import {
  computed,
  effectScope,
  onScopeDispose,
  ref,
  toRaw,
  watch
} from "vue";
import { getCurrentInstance } from "@veno-ui/utils";
const stack = ref([]);
function useStack(isActive) {
  const vm = getCurrentInstance("stack");
  let scope;
  watch(isActive, (val) => {
    if (val) {
      scope = effectScope();
      scope.run(() => {
        stack.value.push(vm);
        onScopeDispose(() => {
          stack.value.splice(stack.value.indexOf(vm), 1);
        });
      });
    } else {
      scope?.stop();
    }
  }, { immediate: true });
  const isTop = computed(() => {
    return toRaw(stack.value[stack.value.length - 1]) === vm;
  });
  return {
    isTop
  };
}
export {
  useStack
};
//# sourceMappingURL=index.mjs.map
