/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

import { computed, ref, onMounted, nextTick } from '@vue/composition-api';
import { o as observe } from '../_chunks/dep-356f585c.js';

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

export { useLazyLoad as default };
//# sourceMappingURL=use-lazy-load.js.map
