/**
 * ldesign v0.2.22
 * (c) 2022/12/7 16:21 built by swimly
 * @license MIT
 */

import { computed, ref, onMounted, nextTick } from '@vue/composition-api';
import { o as observe } from '../_chunks/dep-62ed000f.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?.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?.type !== "lazy") return;
    nextTick(() => {
      const bufferSize = Math.max(10, params.bufferSize || 10);
      const height = tRowHeight.value * bufferSize;
      observe(childRef.value, containerRef?.value, init, height);
    });
  });
  return {
    hasLazyLoadHolder,
    tRowHeight
  };
}

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