"use strict";

exports.__esModule = true;
exports.activateTab = activateTab;
exports.buildTree = buildTree;
exports.setSelectedSize = setSelectedSize;
exports.setDefaultSelectedTab = setDefaultSelectedTab;
exports.removeDefaultNavigation = removeDefaultNavigation;

function activateTab(element) {
  var _element$classList;

  element == null ? void 0 : (_element$classList = element.classList) == null ? void 0 : _element$classList.add('active', 'show');
}

function buildTree() {
  var _document, _document$querySelect;

  return Array.from(((_document = document) == null ? void 0 : (_document$querySelect = _document.querySelector('.nav-tabs')) == null ? void 0 : _document$querySelect.getElementsByTagName('a')) || []).map(function (item) {
    var _Array$from, _childContainer$first;

    var parentId = item.href.slice(item.href.indexOf('#'));
    var childContainer = document.querySelector(parentId);
    var result = {
      parentId: parentId,
      label: item.innerHTML,
      children: []
    };
    (_Array$from = Array.from((childContainer == null ? void 0 : (_childContainer$first = childContainer.firstElementChild) == null ? void 0 : _childContainer$first.getElementsByTagName('div')) || [])) == null ? void 0 : _Array$from.forEach(function (currentItem) {
      var _document$querySelect2;

      if ((_document$querySelect2 = document.querySelector("[href='#" + currentItem.id + "']")) != null && _document$querySelect2.innerHTML) {
        var _document$querySelect3;

        result.children.push({
          label: (_document$querySelect3 = document.querySelector("[href='#" + currentItem.id + "']")) == null ? void 0 : _document$querySelect3.innerHTML,
          parentId: '#' + currentItem.id
        });
      }
    });
    return result;
  });
}

function setSelectedSize(label) {
  document.querySelectorAll('tr').forEach(function (item) {
    var _selectedRow$parentEl;

    var selectedRow = Array.from((item == null ? void 0 : item.children) || []).find(function (x) {
      return x.innerHTML === label;
    });
    selectedRow == null ? void 0 : (_selectedRow$parentEl = selectedRow.parentElement) == null ? void 0 : _selectedRow$parentEl.classList.add('activated');
  });
}

function setDefaultSelectedTab() {
  var _panels$, _panels$$firstElement, _panels$$firstElement2;

  var panels = document.querySelectorAll('.tab-pane');
  panels.forEach(function (item) {
    return item.classList.remove('active', 'show');
  });
  activateTab(panels == null ? void 0 : panels[0]);

  if ((panels == null ? void 0 : (_panels$ = panels[0]) == null ? void 0 : (_panels$$firstElement = _panels$.firstElementChild) == null ? void 0 : (_panels$$firstElement2 = _panels$$firstElement.firstElementChild) == null ? void 0 : _panels$$firstElement2.tagName) !== 'TBODY') {
    var _panels$2, _panels$2$firstElemen;

    activateTab(panels == null ? void 0 : (_panels$2 = panels[0]) == null ? void 0 : (_panels$2$firstElemen = _panels$2.firstElementChild) == null ? void 0 : _panels$2$firstElemen.firstElementChild);
  }
}

function removeDefaultNavigation() {
  document.querySelectorAll('.nav').forEach(function (item) {
    return item.remove();
  });
}
//# sourceMappingURL=utils.js.map