const h = require('react-hyperscript');
const CytoscapeTooltip = require('../../../common/cy/tooltips/cytoscape-tooltip');

const EnrichmentTooltip = require('../enrichment-tooltip');

const { ServerAPI } = require('../../../services');

const ENRICHMENT_MAP_LAYOUT = {
  name: 'cose-bilkent',
  nodeRepulsion: 300000,
  edgeElasticity: 0.05,
  idealEdgeLength: 200,
  animate: false,
  padding: 20
};

const SHOW_ENRICHMENT_TOOLTIPS_EVENT = 'showenrichmenttooltip';

let bindEvents = cy => {
  let hideTooltips = () => {
    cy.elements().forEach(ele => {
      let tooltip = ele.scratch('_tooltip');
      if (tooltip) {
        tooltip.hide();
      }
    });
  };

  cy.on(SHOW_ENRICHMENT_TOOLTIPS_EVENT, 'node[class != "compartment"]', function (evt) {
    let node = evt.target;
    let getEnrichmentTooltipData = () => {
      let id = node.data('id');

      if(/^GO:\d+$/.test(id)) return ServerAPI.getGoInformation( id.replace("GO:", "") );
      else if(/^REAC:\d+$/.test(id)) return ServerAPI.getReactomeInformation( id.replace("REAC:", "R-HSA-") );
      else return Promise.resolve(null);
    };

    getEnrichmentTooltipData().then( result => {
      //default
      let pathwayOverview = null;
      //successful GO API call
      if(result && result.numberOfHits) pathwayOverview = result.results[0].definition.text;
      //successful Reactome API call
      else if(result && result.summation) pathwayOverview = result.summation[0].text;

      let tooltip = new CytoscapeTooltip( node.popperRef(), {
        html: h(EnrichmentTooltip, {
          node: node,
          overviewDesc: pathwayOverview
          })
      } );
      node.scratch('_tooltip', tooltip);
      tooltip.show();
    })
    .catch(err => console.log(err));
  });

  cy.on('tap', evt => {
    const tgt = evt.target;

    // if we didn't click a node, close all tooltips
    if( evt.target === cy || evt.target.isEdge() ){
      hideTooltips();
      return;
    }

    // we clicked a node that has a tooltip open -> close it
    if( tgt.scratch('_tooltip-opened') ){
      hideTooltips();
    } else {
      // open the tooltip for the clicked node
      hideTooltips();
      tgt.emit(SHOW_ENRICHMENT_TOOLTIPS_EVENT);
    }
  });

  //Hide Tooltips on various graph movements
  cy.on('drag', () => hideTooltips());
  cy.on('pan', () => hideTooltips());
  cy.on('zoom', () => hideTooltips());
  cy.on('layoutstart', () => hideTooltips());
};


module.exports = {
  ENRICHMENT_MAP_LAYOUT,
  enrichmentStylesheet: require('./enrichment-stylesheet'),
  bindEvents
};
@@ -863,16 +863,17 @@
      if(
+ 
 /%5EGO:%5Cd+
@@ -875,32 +875,33 @@
 O:%5Cd+$/.test(id)
+ 
 ) return ServerA
@@ -960,16 +960,17 @@
 else if(
+ 
 /%5EREAC:%5C
@@ -982,16 +982,17 @@
 test(id)
+ 
 ) return

add spaces