import { effectScope, nextTick, watchEffect } from "vue";
import { IN_BROWSER, getCurrentInstanceName, propsFactory } from "@veno-ui/utils";
import { closeScrollStrategy } from "./close";
import { blockScrollStrategy } from "./block";
import { repositionScrollStrategy } from "./reposition";
const scrollStrategies = {
  none: null,
  close: closeScrollStrategy,
  block: blockScrollStrategy,
  reposition: repositionScrollStrategy
};
const makeScrollStrategyProps = propsFactory({
  /**
   * @zh 滚动策略
   */
  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?.stop();
    if (!data.isActive.value || !props.scrollStrategy || typeof props.scrollStrategy === "boolean")
      return;
    scope = effectScope();
    await nextTick();
    scope.run(() => {
      if (typeof props.scrollStrategy === "function") {
        props.scrollStrategy(data, name);
      } else if (typeof props.scrollStrategy === "string" && props.scrollStrategy in scrollStrategies) {
        scrollStrategies[props.scrollStrategy]?.(data, name);
      }
    });
  });
}
export {
  makeScrollStrategyProps,
  useScrollStrategy
};
//# sourceMappingURL=index.mjs.map
