import { ref as n, watch as a, unref as r, nextTick as v } from "vue";
function W({ refChatList: t, chats: u, emit: i }) {
  const o = n(!1), s = n(!1), c = n(!1);
  function f() {
    v(function() {
      const l = r(t);
      l && (l.scrollTop = 0);
    });
  }
  const h = () => {
    const l = r(t);
    if (!l) return;
    const e = l.scrollHeight - l.scrollTop - l.clientHeight;
    l.scrollTop > 500 && (s.value = !0), l.scrollTop <= 500 && (s.value = !1), c.value ? e < 300 && (o.value = !0) : (e < 300 && (o.value = !0), e >= 300 && (o.value = !1));
  };
  return a(
    () => o.value,
    () => {
      o.value && i("loadMoreChats");
    }
  ), a(
    u,
    () => {
      if (o.value = !1, c.value) {
        const l = r(t);
        if (!l) return;
        l.scrollTop = l.scrollHeight;
      }
    }
  ), {
    allowLoadMore: o,
    isShowButton: s,
    scrollToTopForce: f,
    scrollCheck: h,
    startScrollWatch: (l) => {
      const e = r(t);
      if (!e) return;
      (l.offsetX > e.clientWidth || l.offsetY > e.clientHeight) && (c.value = !0);
    },
    stopScrollWatch: () => {
      c.value = !1;
    }
  };
}
export {
  W as useChatListScroll
};
