'use babel'

import TabController from './tab_controller'
import { CompositeDisposable } from 'atom'

export default {
  tabControllers: [],
  subscriptions: null,

  activate() {
    this.subscriptions = new CompositeDisposable()

    const initPanes = atom.workspace.getPanes()
    this.tabControllers.push(new TabController(initPanes))

    this.subscriptions.add(atom.commands.add('atom-workspace', {
      'atom-vim-like-tab:hide': () => this.hide(),
      'atom-vim-like-tab:show': () => this.show(),
      'atom-vim-like-tab:new-tab': () => this.createNewTab(),
    }))
  },

  deactivate() {
    this.subscriptions.dispose()
    this.tabControllers.forEach((tabContoller) => { tabContoller.destroy() })
  },

  hide(index = 0) {
    this.tabControllers[index].hide()
  },
  show(index = 0) {
    this.tabControllers[index].show()
  },
  createNewTab() {
    this.tabControllers.forEach((tabContoller) => {
      tabContoller.hide()
    })

    const tabContoller = new TabController
    const activePane = atom.workspace.getActivePane()
    activePane.splitRight()

    this.tabControllers.push(tabContoller)
    console.log(this.tabControllers)
  },

}

@@ -93,16 +93,48 @@
 m 'atom'
+%0Aimport _ from 'underscore-plus'
 %0A%0Aexport
@@ -188,16 +188,32 @@
 s: null,
+%0A  showIndex: 0,
 %0A%0A  acti
@@ -606,24 +606,148 @@
 teNewTab(),%0A
+      'atom-vim-like-tab:next': () =%3E this.showNextTab(),%0A      'atom-vim-like-tab:previous': () =%3E this.showPreviousTab(),%0A
     %7D))%0A  %7D,
@@ -1319,16 +1319,638 @@
 ollers)%0A
+    this.showIndex = this.tabControllers.length - 1%0A  %7D,%0A  showTabByIndex(index) %7B%0A    this.showIndex = this.getValidShowIndex(index)%0A    _.each(this.tabControllers, (tabController, i) =%3E %7B%0A      if (i !== this.showIndex) tabController.hide()%0A    %7D)%0A    this.tabControllers%5Bthis.showIndex%5D.show()%0A  %7D,%0A  showNextTab() %7B%0A    this.showTabByIndex(this.showIndex + 1)%0A  %7D,%0A  showPreviousTab() %7B%0A    this.showTabByIndex(this.showIndex - 1)%0A  %7D,%0A  getValidShowIndex(index) %7B%0A    if (index %3E= this.tabControllers.length) %7B%0A      return 0%0A    %7D else if (index %3C 0) %7B%0A      return this.tabControllers.length%0A    %7D%0A%0A    return index%0A
   %7D,%0A
-%0A
 %7D%0A

add show next and previous tab command