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

'use strict';

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

var vue = require('vue');
var hooks_useVirtualScroll = require('../../hooks/useVirtualScroll.js');
require('@babel/runtime/helpers/defineProperty');

var usePanelVirtualScroll = function usePanelVirtualScroll(props) {
  var _props$scroll3, _props$scroll4, _props$scroll5, _props$scroll6, _props$scroll7;
  var isVirtual = vue.computed(function () {
    var _props$scroll, _props$options$value, _props$scroll2;
    return ((_props$scroll = props.scroll) === null || _props$scroll === void 0 ? void 0 : _props$scroll.type) === "virtual" && ((_props$options$value = props.options.value) === null || _props$options$value === void 0 ? void 0 : _props$options$value.length) > (((_props$scroll2 = props.scroll) === null || _props$scroll2 === void 0 ? void 0 : _props$scroll2.threshold) || 100);
  });
  var _ref = ((_props$scroll3 = props.scroll) === null || _props$scroll3 === void 0 ? void 0 : _props$scroll3.type) === "virtual" ? hooks_useVirtualScroll["default"]({
      container: props.popupContentRef,
      data: props.options,
      fixedHeight: ((_props$scroll4 = props.scroll) === null || _props$scroll4 === void 0 ? void 0 : _props$scroll4.isFixedRowHeight) || false,
      lineHeight: ((_props$scroll5 = props.scroll) === null || _props$scroll5 === void 0 ? void 0 : _props$scroll5.rowHeight) || 28,
      bufferSize: ((_props$scroll6 = props.scroll) === null || _props$scroll6 === void 0 ? void 0 : _props$scroll6.bufferSize) || 20,
      threshold: ((_props$scroll7 = props.scroll) === null || _props$scroll7 === void 0 ? void 0 : _props$scroll7.threshold) || 100
    }) : {},
    _ref$trs = _ref.trs,
    trs = _ref$trs === void 0 ? null : _ref$trs,
    _ref$visibleData = _ref.visibleData,
    visibleData = _ref$visibleData === void 0 ? null : _ref$visibleData,
    _ref$handleScroll = _ref.handleScroll,
    handleVirtualScroll = _ref$handleScroll === void 0 ? null : _ref$handleScroll,
    _ref$scrollHeight = _ref.scrollHeight,
    scrollHeight = _ref$scrollHeight === void 0 ? null : _ref$scrollHeight,
    _ref$translateY = _ref.translateY,
    translateY = _ref$translateY === void 0 ? null : _ref$translateY,
    _ref$handleRowMounted = _ref.handleRowMounted,
    handleRowMounted = _ref$handleRowMounted === void 0 ? null : _ref$handleRowMounted;
  var lastScrollY = -1;
  var onInnerVirtualScroll = function onInnerVirtualScroll(e) {
    if (!isVirtual.value) return;
    var target = e.target;
    var top = target.scrollTop;
    if (Math.abs(lastScrollY - top) > 5) {
      handleVirtualScroll();
      lastScrollY = top;
    } else {
      lastScrollY = -1;
    }
  };
  vue.onMounted(function () {
    var _props$popupContentRe;
    (_props$popupContentRe = props.popupContentRef.value) === null || _props$popupContentRe === void 0 ? void 0 : _props$popupContentRe.addEventListener("scroll", onInnerVirtualScroll);
  });
  vue.onBeforeUnmount(function () {
    var _props$popupContentRe2;
    (_props$popupContentRe2 = props.popupContentRef.value) === null || _props$popupContentRe2 === void 0 ? void 0 : _props$popupContentRe2.removeEventListener("scroll", onInnerVirtualScroll);
  });
  var cursorStyle = vue.computed(function () {
    return {
      "position": "absolute",
      "width": "1px",
      "height": "1px",
      "transition": "transform 0.2s",
      "transform": "translate(0, ".concat(scrollHeight.value, "px)"),
      "-ms-transform": "translate(0, ".concat(scrollHeight.value, "px)"),
      "-moz-transform": "translate(0, ".concat(scrollHeight.value, "px)"),
      "-webkit-transform": "translate(0, ".concat(scrollHeight.value, "px)")
    };
  });
  var panelStyle = vue.computed(function () {
    return {
      "transform": "translate(0, ".concat(translateY.value, "px)"),
      "-ms-transform": "translate(0, ".concat(translateY.value, "px)"),
      "-moz-transform": "translate(0, ".concat(translateY.value, "px)"),
      "-webkit-transform": "translate(0, ".concat(translateY.value, "px)")
    };
  });
  return {
    trs: trs,
    scrollHeight: scrollHeight,
    translateY: translateY,
    visibleData: visibleData,
    handleRowMounted: handleRowMounted,
    isVirtual: isVirtual,
    cursorStyle: cursorStyle,
    panelStyle: panelStyle
  };
};

exports.usePanelVirtualScroll = usePanelVirtualScroll;
//# sourceMappingURL=usePanelVirtualScroll.js.map
