document.addEventListener('DOMContentLoaded', () => {
  function isCompatibleBrowser() {
    if (window.apolloBrowserslistRegex === undefined || window.apolloBrowserslistRegex === null) {
      return false;
    }

    var edgeMobileRegex = /(EdgA|EdgiOS)\/([4-9]\d)/;
    return (
      window.apolloBrowserslistRegex.test(navigator.userAgent) &&
      !edgeMobileRegex.test(navigator.userAgent)
    );
  }

  if (!isCompatibleBrowser()) {
    if (window['gtag']) {
      window['gtag']('event', 'incompatible_browser', {
        event_label: 'browser'
      });
    }

    var browserSupportElement = document.getElementById('browser-support');
    if (browserSupportElement) {
      browserSupportElement.className = browserSupportElement.className.replace('d-none', '');
      var hostElement = document.getElementById('benefits-app-host');
      if (hostElement && hostElement.parentNode) {
        hostElement.parentNode.removeChild(hostElement);

        setTimeout(function () {
          window.parent.postMessage(
            {
              type: 'contentResized',
              height: browserSupportElement.offsetHeight,
              width: -1,
              sender: 'flare'
            },
            '*'
          );
        }, 0);
      }
    }
  }
});
