var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/PisellScrollView/hooks/useScrollEvents.ts
var useScrollEvents_exports = {};
__export(useScrollEvents_exports, {
  useScrollEvents: () => useScrollEvents
});
module.exports = __toCommonJS(useScrollEvents_exports);
var import_react = require("react");
var import_lodash = require("lodash");
var useScrollEvents = ({
  containerRef,
  onScroll,
  onScrollStart,
  onScrollEnd,
  onReachTop,
  onReachBottom,
  onReachLeft,
  onReachRight,
  reachThreshold = 0,
  scrollEndDelay = 150,
  updateScrollState,
  scrollState
}) => {
  const isScrolling = (0, import_react.useRef)(false);
  const handleScrollEnd = (0, import_react.useCallback)(
    (0, import_lodash.debounce)((finalState) => {
      isScrolling.current = false;
      onScrollEnd == null ? void 0 : onScrollEnd(finalState);
    }, scrollEndDelay),
    [onScrollEnd, scrollEndDelay]
  );
  const handleScroll = (0, import_react.useCallback)(() => {
    const container = containerRef.current;
    if (!container) return;
    updateScrollState();
    const {
      scrollTop,
      scrollLeft,
      scrollHeight,
      scrollWidth,
      clientHeight,
      clientWidth
    } = container;
    const maxScrollTop = Math.max(0, scrollHeight - clientHeight);
    const maxScrollLeft = Math.max(0, scrollWidth - clientWidth);
    const percentY = maxScrollTop > 0 ? scrollTop / maxScrollTop * 100 : 0;
    const percentX = maxScrollLeft > 0 ? scrollLeft / maxScrollLeft * 100 : 0;
    const isScrollToTop = scrollTop <= reachThreshold;
    const isScrollToBottom = scrollTop + clientHeight >= scrollHeight - reachThreshold;
    const isScrollToLeft = scrollLeft <= reachThreshold;
    const isScrollToRight = scrollLeft + clientWidth >= scrollWidth - reachThreshold;
    const isOverflows = scrollHeight > clientHeight || scrollWidth > clientWidth;
    const currentData = {
      scrollTop,
      scrollLeft,
      scrollHeight,
      scrollWidth,
      clientHeight,
      clientWidth,
      percentY,
      percentX,
      direction: null,
      // 在这里计算方向比较麻烦，可以使用 scrollState 中的（虽然有一点延迟）
      isScrollToTop,
      isScrollToBottom,
      isScrollToLeft,
      isScrollToRight,
      isOverflows
    };
    if (!isScrolling.current) {
      isScrolling.current = true;
      onScrollStart == null ? void 0 : onScrollStart(currentData);
    }
    onScroll == null ? void 0 : onScroll(currentData);
    if (scrollTop <= reachThreshold) onReachTop == null ? void 0 : onReachTop(currentData);
    if (scrollTop + clientHeight >= scrollHeight - reachThreshold) onReachBottom == null ? void 0 : onReachBottom(currentData);
    if (scrollLeft <= reachThreshold) onReachLeft == null ? void 0 : onReachLeft(currentData);
    if (scrollLeft + clientWidth >= scrollWidth - reachThreshold) onReachRight == null ? void 0 : onReachRight(currentData);
    handleScrollEnd(currentData);
  }, [
    containerRef,
    updateScrollState,
    onScroll,
    onScrollStart,
    handleScrollEnd,
    onReachTop,
    onReachBottom,
    onReachLeft,
    onReachRight,
    reachThreshold
  ]);
  return { handleScroll };
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  useScrollEvents
});
