"use strict";
const uni_modules_tdesignUniapp_components_common_utils = require("../common/utils.js");
const uni_modules_tdesignUniapp_components_common_bus = require("../common/bus.js");
const bus = new uni_modules_tdesignUniapp_components_common_bus.Bus();
const PAGE_SCROLL_EVENT_NAME = "page-scroll";
const onPageScroll = function(event) {
  const page = uni_modules_tdesignUniapp_components_common_utils.getCurrentPage();
  if (!page)
    return;
  const { pageScroller } = page;
  pageScroller == null ? void 0 : pageScroller.forEach((scroller) => {
    if (typeof scroller === "function") {
      scroller(event);
    }
  });
};
const pageScrollMixin = (funcName = "onScroll", useBus = true) => {
  return {
    mounted() {
      if (useBus) {
        bus.on(PAGE_SCROLL_EVENT_NAME, this[funcName]);
        return;
      }
      const page = uni_modules_tdesignUniapp_components_common_utils.getCurrentPage();
      if (!page)
        return;
      if (Array.isArray(page.pageScroller)) {
        page.pageScroller.push(this._bindScroller);
      } else {
        page.pageScroller = typeof page.onPageScroll === "function" ? [page.onPageScroll.bind(page), this._bindScroller] : [this._bindScroller];
      }
      page.onPageScroll = onPageScroll;
    },
    beforeUnMount() {
      var _a;
      if (useBus) {
        bus.off(PAGE_SCROLL_EVENT_NAME, this[funcName]);
        return;
      }
      const page = uni_modules_tdesignUniapp_components_common_utils.getCurrentPage();
      if (!page)
        return;
      page.pageScroller = ((_a = page.pageScroller) == null ? void 0 : _a.filter((item) => item !== this._bindScroller)) || [];
    },
    methods: {
      _bindScroller(e) {
        var _a;
        let result;
        result = (_a = this[funcName]) == null ? void 0 : _a.call(this, e);
        return result;
      }
    }
  };
};
exports.pageScrollMixin = pageScrollMixin;
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/uni_modules/tdesign-uniapp/components/mixins/page-scroll.js.map
