"use strict";

exports.__esModule = true;
exports.useScrollParent = useScrollParent;

var _vue = require("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;
}

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