import { findChild, findAllChildren } from '../util/domHelpers'

export default class FootnoteConverter {
  get type () { return 'fn' }

  get tagName () { return 'fn' }

  import (el, node, importer) {
    // TODO: at some point we want to retain the label and determine if the label should be treated as custom
    // or be generated
    let labelEl = findChild(el, 'label')
    let pEls = findAllChildren(el, 'p')

    if (labelEl) {
      node.label = labelEl.text()
    }
    node._childNodes = pEls.map(el => importer.convertElement(el).id)
  }

  export (node, el, exporter) {
    const $$ = exporter.$$
    el.append($$('label').text(node.label))
    el.append(node.getChildren().map(p => exporter.convertNode(p)))
  }
}

@@ -57,16 +57,194 @@
 elpers'%0A
+import %7B getLabel %7D from '../../shared/nodeHelpers'%0A%0A// TODO: at some point we want to retain the label and determine if the label should be treated as custom%0A// or be generated.
 %0Aexport 
@@ -378,141 +378,8 @@
 ) %7B%0A
-    // TODO: at some point we want to retain the label and determine if the label should be treated as custom%0A    // or be generated%0A
     
@@ -455,17 +455,16 @@
 l, 'p')%0A
-%0A
     if (
@@ -648,16 +648,539 @@
 rter.$$%0A
+    // We gonna need to find another way for node states. I.e. for labels we will have%0A    // a hybrid scenario where the labels are either edited manually, and thus we need to record ops,%0A    // or they are generated without persisting operations (e.g. think about undo/redo, or collab)%0A    // my suggestion would be to introduce volatile ops, they would be excluded from the DocumentChange, that is stored in the change history,%0A    // or used for collaborative editing.%0A    let label = getLabel(node)%0A    if (label) %7B%0A  
     el.a
@@ -1206,21 +1206,16 @@
 ext(
-node.
 label))%0A
     
@@ -1210,16 +1210,22 @@
 label))%0A
+    %7D%0A
     el.a

Fix export of footnote labels.