function isFunction(obj) {
  return typeof obj === 'function';
}
export function isHidden(el, root) {
  if (!el) {
    return true;
  }
  if (el.style.display === 'none') {
    return true;
  }
  if (el.style.visibility === 'hidden') {
    return true;
  }
  let style = window.getComputedStyle(el);
  if (style.display === 'none') {
    return true;
  }
  if (style.visibility === 'hidden') {
    return true;
  }
  let node = el.parentElement;
  if (node !== root) {
    return isHidden(node, root);
  }
  return false;
}
export 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;
  }
}
;
export function getFocusableItems(el, filter) {
  let items = [];
  let itemNodes = el.querySelectorAll('[tabindex], a, button, input, textarea, select, [role="button"]');
  if (!itemNodes || !itemNodes.length) {
    return items;
  }
  let item;
  for (let 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;
}
