'use strict';

exports.__esModule = true;
exports.isHidden = isHidden;
exports.isFocusable = isFocusable;
exports.getFocusableItems = getFocusableItems;
function isFunction(obj) {
  return typeof obj === 'function';
}
function isHidden(el, root) {
  if (!el) {
    return true;
  }
  if (el.style.display === 'none') {
    return true;
  }
  if (el.style.visibility === 'hidden') {
    return true;
  }
  var style = window.getComputedStyle(el);
  if (style.display === 'none') {
    return true;
  }
  if (style.visibility === 'hidden') {
    return true;
  }
  var node = el.parentElement;
  if (node !== root) {
    return isHidden(node, root);
  }
  return false;
}
function isFocusable(el) {
  if (el.tabIndex > 0 || el.tabIndex === 0 && el.getAttribute('tabIndex') !== null) {
    return true;
  }
  if (el.tabIndex < 0) {
    return false;
  }
  if (el.disabled) {
    return false;
  }
  switch (el.nodeName) {
    case 'A':
      return !!el.href && el.rel !== 'ignore';
    case 'INPUT':
      return el.type !== 'hidden' && el.type !== 'file';
    case 'BUTTON':
    case 'SELECT':
    case 'TEXTAREA':
      return true;
    default:
      return false;
  }
}
;
function getFocusableItems(el, filter) {
  var items = [];
  var itemNodes = el.querySelectorAll('[tabindex], a, button, input, textarea, select, [role="button"]');
  if (!itemNodes || !itemNodes.length) {
    return items;
  }
  var item = void 0;
  for (var i = 0; i < itemNodes.length; i++) {
    item = itemNodes[i];
    if (isFunction(filter)) {
      if (!filter(item)) {
        continue;
      }
    }
    if (isFocusable(item) && !isHidden(item, el)) {
      items.push(item);
    }
  }
  return items;
}