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

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var VueCompositionAPI = require('@vue/composition-api');
var observe = require('../chunks/observe.js');

function useLazyLoad(containerRef, childRef, params) {
  const tRowHeight = VueCompositionAPI.computed(() => Math.max(params.rowHeight || 48, 48));
  const isInit = VueCompositionAPI.ref(params.rowIndex === 0);
  const hasLazyLoadHolder = VueCompositionAPI.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;
      });
    }
  };
  VueCompositionAPI.onMounted(() => {
    if ((params === null || params === void 0 ? void 0 : params.type) !== "lazy") return;
    VueCompositionAPI.nextTick(() => {
      const bufferSize = Math.max(10, params.bufferSize || 10);
      const height = tRowHeight.value * bufferSize;
      observe.observe(childRef.value, containerRef === null || containerRef === void 0 ? void 0 : containerRef.value, init, height);
    });
  });
  return {
    hasLazyLoadHolder,
    tRowHeight
  };
}

exports["default"] = useLazyLoad;
//# sourceMappingURL=use-lazy-load.js.map
