import { _ as _defineProperty } from './defineProperty-62acccfc.js';

//获取替换字段
var getReplaceField = function getReplaceField(mode, repl, tableP, treeP) {
  var t = {};
  if (mode === "tree") t = treeP === null || treeP === void 0 ? void 0 : treeP.replaceFields;else t = tableP === null || tableP === void 0 ? void 0 : tableP.replaceFields;
  return Object.assign(Object.assign({}, repl), t);
};
//to array
var toArray = function toArray(list) {
  if (!list) return [];
  return Array.isArray(list) ? list : JSON.stringify(list) === "{}" ? [] : [list];
};
var isRemoteLoad = function isRemoteLoad(mode, props) {
  if (mode === "table") {
    return !(props && Array.isArray(props.data));
  }
  return !(props && Array.isArray(props.treeData));
};
var getOverlaySize = function getOverlaySize(mode) {
  var isRemoteLoad = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  var maxHeight = arguments.length > 2 ? arguments[2] : undefined;
  var height = arguments.length > 3 ? arguments[3] : undefined;
  var _a;
  var screenH = 720;
  var treeOverlay = "".concat(maxHeight || 254, "px");
  var listOverlay = "".concat(maxHeight || 232, "px");
  // let largeScreenH = 880;
  var largeTreeOverlayH = "".concat(maxHeight || 338, "px");
  var largeListOverlayH = "".concat(maxHeight || 304, "px");
  var clientH = document.documentElement.clientHeight;
  var fixHeight = height !== undefined ? "height" : "maxHeight";
  if (mode === "tree") {
    //tree
    if (clientH <= screenH) {
      //小屏幕
      return isRemoteLoad ? {
        height: treeOverlay
      } : _defineProperty({}, fixHeight, treeOverlay);
    }
    //大屏幕
    return isRemoteLoad ? {
      height: largeTreeOverlayH
    } : _defineProperty({}, fixHeight, largeTreeOverlayH);
  } else if (mode === "list") {
    //list
    if (clientH <= screenH) {
      return isRemoteLoad ? {
        height: listOverlay
      } : _defineProperty({}, fixHeight, listOverlay);
    }
    return isRemoteLoad ? {
      height: largeListOverlayH
    } : _defineProperty({}, fixHeight, largeListOverlayH);
  } else {
    //table
    return {
      height: "".concat((_a = maxHeight !== null && maxHeight !== void 0 ? maxHeight : height) !== null && _a !== void 0 ? _a : 360, "px")
    };
  }
};
// 实现一个防抖函数，debounce接受一个函数func和delay时间作为参数,返回一个防抖函数。使用泛型T保证返回防抖函数的类型与原func一致
function debounce(func, delay) {
  var timer;
  return function () {
    var _this = this;
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    if (timer) clearTimeout(timer);
    timer = setTimeout(function () {
      func.apply(_this, args);
    }, delay);
  };
}
/**
 * @description 查询元素是不是在父元素内
 * @param {HTMLElement} el 当前元素
 * @param {any} parent 父元素的匹配器
 */
var closest = function closest(el, selector) {
  var matchesSelector = el.matches || el.webkitMatchesSelector || el.mozMatchesSelector || el.msMatchesSelector;
  while (el) {
    if (matchesSelector.call(el, selector)) {
      break;
    }
    el = el.parentElement;
  }
  return el;
};

export { getOverlaySize as a, closest as c, debounce as d, getReplaceField as g, isRemoteLoad as i, toArray as t };
