import { ref, onMounted } from 'vue';
var overflowScrollReg = /scroll|auto/i;

function isElement(node) {
  var ELEMENT_NODE_TYPE = 1;
  return node.tagName !== 'HTML' && node.tagName !== 'BODY' && node.nodeType === ELEMENT_NODE_TYPE;
} // https://github.com/youzan/vant/issues/3823


function getScrollParent(el, root) {
  if (root === void 0) {
    root = window;
  }

  var node = el;

  while (node && node !== root && isElement(node)) {
    var _window$getComputedSt = window.getComputedStyle(node),
        overflowY = _window$getComputedSt.overflowY;

    if (overflowScrollReg.test(overflowY)) {
      return node;
    }

    node = node.parentNode;
  }

  return root;
}

export function useScrollParent(el) {
  var scrollParent = ref();
  onMounted(function () {
    if (el.value) {
      scrollParent.value = getScrollParent(el.value);
    }
  });
  return scrollParent;
}