import { ref as a, watch as u, nextTick as s } from "vue";
function f({ feedRef: e, objectsRef: i, scrollToBottomRef: m }) {
  const l = a(!1);
  function r() {
    s(() => {
      const t = e.value;
      t && (t.style.scrollBehavior = "auto", t.scrollTop = t.scrollHeight, s(() => {
        t.scrollHeight - t.scrollTop - t.clientHeight > 10 && (t.scrollTop = t.scrollHeight);
      }), setTimeout(() => {
        t.style.scrollBehavior = "smooth";
      }, 1e3));
    });
  }
  function o() {
    const t = e.value;
    if (!t) return;
    const n = () => {
      t.scrollHeight - t.scrollTop - t.clientHeight < 5 || (t.scrollTop = t.scrollHeight, setTimeout(() => {
        t.scrollHeight - t.scrollTop - t.clientHeight > 5 && (t.scrollTop = t.scrollHeight);
      }, 200));
    };
    n(), setTimeout(n, 300);
  }
  function c() {
    !l.value && i.value.length > 0 && (r(), setTimeout(() => {
      o();
    }, 300), setTimeout(() => {
      o();
    }, 800), l.value = !0);
  }
  function h() {
    s(() => {
      const t = e.value;
      t && (t.style.scrollBehavior = "smooth", t.scrollTop = t.scrollHeight);
    });
  }
  return u(
    () => m.value,
    (t) => {
      t && (r(), setTimeout(() => {
        o();
      }, 500), setTimeout(() => {
        o();
      }, 1200));
    },
    { immediate: !0 }
  ), u(
    () => i.value.length,
    () => {
      !l.value && i.value.length > 0 && c();
    },
    { immediate: !0 }
  ), {
    isInitialized: l,
    performScrollToBottom: r,
    ensureScrollToBottom: o,
    initializeScroll: c,
    smoothScrollToBottom: h
  };
}
export {
  f as useFeedScroll
};
