/**
 * tdesign v0.41.7
 * (c) 2022 tdesign
 * @license MIT
 */

'use strict';

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

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

function useLazyLoad(containerRef, childRef, params) {
  var tRowHeight = VueCompositionAPI.computed(function () {
    return Math.max(params.rowHeight || 48, 48);
  });
  var isInit = VueCompositionAPI.ref(params.rowIndex === 0);
  var hasLazyLoadHolder = VueCompositionAPI.computed(function () {
    return (params === null || params === void 0 ? void 0 : params.type) === "lazy" && !isInit.value;
  });

  var requestAnimationFrame = (typeof window === "undefined" ? false : window.requestAnimationFrame) || function (cb) {
    return setTimeout(cb, 16.6);
  };

  var init = function init() {
    if (!isInit.value) {
      requestAnimationFrame(function () {
        isInit.value = true;
      });
    }
  };

  VueCompositionAPI.onMounted(function () {
    if ((params === null || params === void 0 ? void 0 : params.type) !== "lazy") return;
    VueCompositionAPI.nextTick(function () {
      var bufferSize = Math.max(10, params.bufferSize || 10);
      var height = tRowHeight.value * bufferSize;
      _common_js_utils_observe["default"](childRef.value, containerRef.value, init, height);
    });
  });
  return {
    hasLazyLoadHolder: hasLazyLoadHolder,
    tRowHeight: tRowHeight
  };
}

exports["default"] = useLazyLoad;
//# sourceMappingURL=useLazyLoad.js.map
