'use babel';

import SelectSimilarRclickView from './select-similar-rclick-view';
import { CompositeDisposable } from 'atom';

export default {

  selectSimilarRclickView: null,
  modalPanel: null,
  subscriptions: null,

  activate(state) {
    this.selectSimilarRclickView = new SelectSimilarRclickView(state.selectSimilarRclickViewState);
    this.modalPanel = atom.workspace.addModalPanel({
      item: this.selectSimilarRclickView.getElement(),
      visible: false
    });

    // Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
    this.subscriptions = new CompositeDisposable();

    // Register command that toggles this view
    this.subscriptions.add(atom.commands.add('atom-workspace', {
      'select-similar-rclick:toggle': () => this.toggle()
    }));
    this.subscriptions.add(atom.commands.add('atom-workspace', {
      'select-similar-rclick:selectSimilar': () => this.selectSimilar()
    }));
  },

  deactivate() {
    this.modalPanel.destroy();
    this.subscriptions.dispose();
    this.selectSimilarRclickView.destroy();
  },

  serialize() {
    return {
      selectSimilarRclickViewState: this.selectSimilarRclickView.serialize()
    };
  },

  toggle() {
    console.log('SelectSimilarRclick was toggled!');
    return (
      this.modalPanel.isVisible() ?
      this.modalPanel.hide() :
      this.modalPanel.show()
    );
  },

  selectSimilar() {
// atom.workspaceView.trigger("find-and-replace:select-all")
    // atom.commands.dispatch(atom.views.getView(atom.workspace), "find-and-replace:select-all");
  // editor = atom.workspace.getActiveEditor()
editorView = atom.views.getView(atom.workspace);
atom.commands.dispatch(editorView, 'find-and-replace:select-all');
    console.log('Colabolla!');
    return (0);
  }
};
