/**
 * ldesign v0.4.2
 * (c) 2023 ldesign
 * @license MIT
 */

import { computed, ref, onMounted, nextTick } from 'vue';
import observe from '../../_common/js/utils/observe.mjs';
import { isServer } from '../../utils/dom.mjs';
import '../../_chunks/dep-a0b4a044.mjs';
import '../../_chunks/dep-1cf2b129.mjs';
import '../../_chunks/dep-c959a6fb.mjs';
import '../../_chunks/dep-b4041200.mjs';
import '../../_chunks/dep-e3b14d70.mjs';
import '../../_chunks/dep-66d6733b.mjs';
import '../../_chunks/dep-c31e1d9e.mjs';
import '../../_chunks/dep-6b22dd27.mjs';
import '../../_chunks/dep-0f0c89ff.mjs';
import '../../utils/easing.mjs';

function useLazyLoad(containerRef, childRef, params) {
  var tRowHeight = computed(function () {
    return Math.max(params.rowHeight || 48, 48);
  });
  var isInit = ref(false);
  var hasLazyLoadHolder = computed(function () {
    return (params === null || params === void 0 ? void 0 : params.type) === "lazy" && !isInit.value;
  });
  var requestAnimationFrame = !isServer && window.requestAnimationFrame || function (cb) {
    return setTimeout(cb, 16.6);
  };
  var init = function init() {
    if (!isInit.value) {
      requestAnimationFrame(function () {
        isInit.value = true;
      });
    }
  };
  onMounted(function () {
    if ((params === null || params === void 0 ? void 0 : params.type) !== "lazy") return;
    nextTick(function () {
      var bufferSize = Math.max(10, params.bufferSize || 10);
      var height = tRowHeight.value * bufferSize;
      observe(childRef.value, containerRef.value, init, height);
    });
  });
  return {
    hasLazyLoadHolder: hasLazyLoadHolder,
    tRowHeight: tRowHeight
  };
}

export { useLazyLoad as default };
//# sourceMappingURL=useLazyLoad.mjs.map
