/* eslint-disable no-undef */

var openedTooltip = {};

// eslint-disable-next-line @typescript-eslint/no-unused-vars
function openTooltip(element, popupHref) {
  const id =
    element.parentElement.firstElementChild.textContent.trim() +
    element.text.trim();
  if (id in openedTooltip) {
    delete openedTooltip[id];
    window.setTimeout(() => {
      $(element).popover('hide');
    });
  } else {
    for (const otherElement of Object.values(openedTooltip)) {
      window.setTimeout(() => {
        $(otherElement).popover('hide');
      });
    }
    openedTooltip = { [id]: element };
    if (!element.getAttribute('data-content')) {
      // eslint-disable-next-line @typescript-eslint/no-floating-promises
      loadPopup(popupHref).then((popup) => {
        element.setAttribute('data-content', popup);

        $(element).popover('show');
      });
    }
  }
}
