import options from './options'
import { getCurrentManipulation } from './manipulation'

const nodes = new vis.DataSet([])
const edges = new vis.DataSet([])

const select   = $('select')
const resetBtn = $('#reset-btn')
const testStr  = $('input[name="testStr"]')

const alphabetPromptText = 'Please enter alphabet string: '

let currentVisualizer = 'DFA'

select.material_select()
select.change(onVisualizerChange)
resetBtn.click(e => start(prompt(alphabetPromptText)))
testStr.keypress(e => clickRunBtn(e.which))

start('01')

function start(alphabetStr) {
    if (!alphabetStr)
        return

    const alphabet = [ ...new Set(alphabetStr.split('')) ]

    $('#alphabet .collection-item').remove()

    for (let a of alphabet)
        $('#alphabet').append(`<li class="collection-item">${a}</li>`)

    $('.opt').hide()

    $('#title').text(currentVisualizer)

    nodes.clear()
    edges.clear()
    new vis.Network(document.getElementById('app'), { nodes, edges}, 
                    options(getCurrentManipulation(
                        currentVisualizer, alphabet, { nodes, edges })))
}

function onVisualizerChange() {
    const visSelection = select.val()
    if (currentVisualizer !== visSelection) {
        let alphabetStr = prompt(alphabetPromptText)

        if (!alphabetStr) {
            select.val(currentVisualizer)
            return
        }

        currentVisualizer = visSelection
        start(alphabetStr)
    }
}

function clickRunBtn(key) {
    if (key === 13)
        $('#run-btn').click()
}
@@ -649,24 +649,27 @@
 ('')) %5D%0A%0A   
+ //
  $('#alphabe
@@ -702,16 +702,19 @@
 e()%0A%0A   
+ //
  for (le
@@ -729,24 +729,27 @@
 lphabet)%0A   
+ //
      $('#alp

Remove redundant alphabet manipulation