"use strict";

exports.__esModule = true;
exports.scrollParentToElement = scrollParentToElement;
exports.getScrollParent = getScrollParent;
exports.deepSearch = deepSearch;
exports.hasArrLength = void 0;

/**
 *
 * @export 滚动到指定的dom位置
 * @param {*} element
 */
function scrollParentToElement(element) {
  var parent = getScrollParent(element);
  parent.scrollTop = element.offsetTop - parent.offsetTop;
}
/**
 *
 *
 * @export  查询父级的滚动的dom
 * @param {*} element
 * @return {*}
 */


function getScrollParent(element) {
  var style = window.getComputedStyle(element);
  var excludeStaticParent = style.position === 'absolute';
  var overflowRegex = /(auto|scroll)/;
  if (style.position === 'fixed') return document.body;

  for (var parent = element; parent = parent.parentElement;) {
    style = window.getComputedStyle(parent);

    if (excludeStaticParent && style.position === 'static') {
      continue;
    }

    if (overflowRegex.test(style.overflow + style.overflowY + style.overflowX)) {
      return parent;
    }
  }

  return document.body;
}

function deepSearch(val, arr) {
  if (!arr.length) {
    return;
  }

  var item = null;
  arr.some(function iter(ele) {
    var id = ele.id,
        children = ele.children;

    if (id === val) {
      item = ele;
      return true;
    }

    if (children && children.length) {
      children.some(iter);
    }
  });
  return item;
}

var hasArrLength = function hasArrLength(data) {
  return Array.isArray(data) && !!data.length;
};

exports.hasArrLength = hasArrLength;