// expose the attribures of the nodes

const rmElement = require('../helpers/rmElement.js')

let buttonToken = false
module.exports = function expose (cy) {
  // when button is pressed
  const exposeButton = document.getElementById('expose-button')

  if (buttonToken === false) {
    const graph = document.getElementById('window-id')

    cy.nodes().map(node => {
      let nodeInfo = ''
      const nodeData = node.data().asto
      Object.keys(nodeData).map(i => {
        // adds the keys of the object to the string
        if (nodeData.hasOwnProperty(i) === true) {
          nodeInfo = `${nodeInfo} • ${i}:`
        }
        // adds the values of the object to the string
        nodeInfo = `${nodeInfo} ${nodeData[i]}\n`
      })

      // create a container for each node
      const container = document.createElement('span')
      container.id = node.data().id
      container.innerHTML = `<div class="container-node" style='display: block; margin:0; opacity: 1; left: ${
        node.renderedPosition().x
      }px; top: ${
        node.renderedPosition().y
      }px;'><div class="container-node-info" style='margin: 0;'><span>${nodeInfo}</span></div></div>`

      graph.appendChild(container)
    })

    // show active expose with colored button
    exposeButton.setAttribute('class', 'active-button')
    buttonToken = true
  } else {
    // removes the exposed containers
    cy.nodes().map(node => {
      rmElement('window-id', node.data().id)
    })

    // restores the original button color
    exposeButton.setAttribute('class', 'button-icon')
    buttonToken = false
  }
}

@@ -91,20 +91,17 @@
 )%0A%0Alet b
-utto
+t
 nToken =
@@ -151,36 +151,8 @@
 ) %7B%0A
-  // when button is pressed%0A
   co
@@ -162,20 +162,17 @@
  exposeB
-utto
+t
 n = docu
@@ -213,19 +213,44 @@
 ')%0A%0A
+  // when button is pressed%0A
   if (b
-utto
+t
 nTok
@@ -1251,36 +1251,33 @@
 tton%0A    exposeB
-utto
+t
 n.setAttribute('
@@ -1298,36 +1298,33 @@
 e-button')%0A    b
-utto
+t
 nToken = true%0A  
@@ -1505,20 +1505,17 @@
  exposeB
-utto
+t
 n.setAtt
@@ -1550,20 +1550,17 @@
 ')%0A    b
-utto
+t
 nToken =

rename button -> btn