import { j as g } from "../../node_modules/react/jsx-runtime.mjs";
import { forwardRef as T, useState as E, useRef as L, useMemo as d, useEffect as e, useImperativeHandle as v } from "react";
import l from "../../node_modules/prop-types/index.mjs";
import x from "../../node_modules/better-scroll/dist/better-scroll.esm.mjs";
import { debounce as m } from "../../node_modules/throttle-debounce/esm/index.mjs";
const b = T((u, h) => {
  const [o, s] = E(), i = L(), { direction: f, click: w, refresh: D, pullUpLoading: y, pullDownLoading: P, bounceTop: S, bounceBottom: B } = u, { pullUp: n, pullDown: t, onScroll: c } = u, p = d(() => m(500, n), [n]), a = d(() => m(500, t), [t]);
  return e(() => {
    const r = new x(i.current, {
      scrollX: f === "horizental",
      scrollY: f === "vertical",
      probeType: 3,
      click: w,
      bounce: {
        top: S,
        bottom: B
      }
    });
    return s(r), () => {
      s(null);
    };
  }, []), e(() => {
    if (!(!o || !c))
      return o.on("scroll", c), () => {
        o.off("scroll", c);
      };
  }, [c, o]), e(() => {
    if (!o || !n)
      return;
    const r = () => {
      o.y <= o.maxScrollY + 100 && p();
    };
    return o.on("scrollEnd", r), () => {
      o.off("scrollEnd", r);
    };
  }, [n, p, o]), e(() => {
    if (!o || !t)
      return;
    const r = (U) => {
      U.y > 50 && a();
    };
    return o.on("touchEnd", r), () => {
      o.off("touchEnd", r);
    };
  }, [t, a, o]), e(() => {
    D && o && o.refresh();
  }), v(h, () => ({
    refresh() {
      o && (o.refresh(), o.scrollTo(0, 0));
    },
    getBScroll() {
      if (o)
        return o;
    }
  })), g.jsx("div", { className: "scroll_container", ref: i, children: u.children });
});
b.defaultProps = {
  direction: "vertical",
  click: !0,
  refresh: !0,
  onScroll: null,
  pullUpLoading: !1,
  pullDownLoading: !1,
  pullUp: null,
  pullDown: null,
  bounceTop: !0,
  bounceBottom: !0
};
b.propTypes = {
  direction: l.oneOf(["vertical", "horizental"]),
  refresh: l.bool,
  onScroll: l.func,
  pullUp: l.func,
  pullDown: l.func,
  pullUpLoading: l.bool,
  pullDownLoading: l.bool,
  bounceTop: l.bool,
  //是否支持向上吸顶
  bounceBottom: l.bool
  //是否支持向下吸顶
};
export {
  b as default
};
