// @Author Ann Yanich
// This little code opens a page with the agb forwarding graph in a new window.
// If the page is already opened, it will send a message to that window to tell
// it to navigate to the AGB with the given ID.
let graphViewerWindow = null;

function openGraphViewerWindow(agbId) {
  if (graphViewerWindow === null || graphViewerWindow.closed) {
    graphViewerWindow = window.open(
      `/config/viewAgbForwardingGraph/${agbId}`,
      'agbForwardingGraph',
      'width=500,height=800'
    );
    graphViewerWindow.focus();
  } else {
    graphViewerWindow.postMessage({ type: 'navigateToAgb', agbId }, '*');
    graphViewerWindow.focus();
  }
}

window.openGraphViewerWindow = openGraphViewerWindow;
