import { useRafFn as b } from "@vueuse/core";
import "../../scroll-bar/index.mjs";
import "../../utils/index.mjs";
import { ensureRangeValue as s } from "../../scroll-bar/utils/index.mjs";
import { isDef as f } from "../../utils/is.mjs";
const g = () => {
}, h = (i) => 1 - (1 - i) ** 3, Y = ({
  scrollOffset: i,
  maxScrollDistance: a,
  timer: l = 500,
  onScroll: m = g,
  onScrollEnd: T = g
}) => {
  let u, e, t, o, n;
  const { pause: r, resume: d, isActive: p } = b(
    () => {
      const D = Date.now() - u, c = s(D / l, 0, 1), y = h(c);
      c === 1 ? (o && (i.x = t.x), n && (i.y = t.y), r(), m(o, n), T(o, n)) : (o && (t.x > e.x ? i.x = s(
        e.x + (t.x - e.x) * y,
        e.x,
        a.x
      ) : i.x = s(
        t.x + (e.x - t.x) * (1 - y),
        0,
        e.x
      )), n && (t.y > e.y ? i.y = s(
        e.y + (t.y - e.y) * y,
        e.y,
        a.y
      ) : i.y = s(
        t.y + (e.y - t.y) * (1 - y),
        0,
        e.y
      )), m(o, n));
    },
    { immediate: !1 }
  );
  function v(x) {
    p.value && r(), u = Date.now(), e = {
      x: i.x,
      y: i.y
    }, t = x, o = f(x.x), n = f(x.y), d();
  }
  function w() {
    r();
  }
  return { start: v, stop: w, isActive: p };
};
export {
  Y as useScrollSmooth
};
