import { watchEffect, effectScope, nextTick } from "vue";
import { closeScrollStrategy } from "./close.mjs";
import { blockScrollStrategy } from "./block.mjs";
import { repositionScrollStrategy } from "./reposition.mjs";
import { propsFactory, IN_BROWSER, getCurrentInstanceName } from "../../utils/dist/index.mjs";
const scrollStrategies = {
  none: null,
  close: closeScrollStrategy,
  block: blockScrollStrategy,
  reposition: repositionScrollStrategy
};
const makeScrollStrategyProps = propsFactory({
  scrollStrategy: {
    type: [Boolean, String, Function],
    default: "block",
    validator: (val) => typeof val === "function" || typeof val === "boolean" || val in scrollStrategies
  }
});
function useScrollStrategy(props, data, name = getCurrentInstanceName()) {
  if (!IN_BROWSER)
    return;
  let scope;
  watchEffect(async () => {
    scope == null ? void 0 : scope.stop();
    if (!data.isActive.value || !props.scrollStrategy || typeof props.scrollStrategy === "boolean")
      return;
    scope = effectScope();
    await nextTick();
    scope.run(() => {
      var _a;
      if (typeof props.scrollStrategy === "function") {
        props.scrollStrategy(data, name);
      } else if (typeof props.scrollStrategy === "string" && props.scrollStrategy in scrollStrategies) {
        (_a = scrollStrategies[props.scrollStrategy]) == null ? void 0 : _a.call(scrollStrategies, data, name);
      }
    });
  });
}
export {
  makeScrollStrategyProps,
  useScrollStrategy
};
//# sourceMappingURL=index.mjs.map
