/* @flow */

import React from "react";
import { Disposable } from "atom";

import StatusBar from "./status-bar-component";
import SignalListView from "./signal-list-view";

import { reactFactory } from "../../../utils";

import type { Store } from "../../../store";
import type Kernel from "../../../kernel";
import type MarkerStore from "../../../store/markers";

export class StatusBarConsumer {
  signalListView: SignalListView;
  handleKernelCommand: Function;

  addStatusBar(
    store: Store,
    statusBar: atom$StatusBar,
    handleKernelCommand: Function
  ) {
    const statusBarElement = document.createElement("div");
    statusBarElement.classList.add("inline-block", "hydrogen");

    const statusBarTile = statusBar.addLeftTile({
      item: statusBarElement,
      priority: 100
    });

    this.handleKernelCommand = handleKernelCommand;

    const onClick = ({ kernel, markers }) => {
      this.showKernelCommands({ kernel, markers });
    };

    reactFactory(
      <StatusBar store={store} onClick={onClick} />,
      statusBarElement
    );

    const disposable = new Disposable(() => statusBarTile.destroy());
    store.subscriptions.add(disposable);
    return disposable;
  }

  showKernelCommands({
    kernel,
    markers
  }: {
    kernel: Kernel,
    markers: MarkerStore
  }) {
    let signalListView = this.signalListView;
    signalListView = new SignalListView(kernel);
    signalListView.onConfirmed = (kernelCommand: { command: string }) =>
      this.handleKernelCommand(kernelCommand, { kernel, markers });
    this.signalListView = signalListView;
    signalListView.toggle();
  }
}

const statusBarConsumer = new StatusBarConsumer();
export default statusBarConsumer;

@@ -429,41 +429,8 @@
 iew;
-%0A  handleKernelCommand: Function;
 %0A%0A  
@@ -840,35 +840,28 @@
 lick = (
-%7B kernel, markers %7D
+store: Store
 ) =%3E %7B%0A 
@@ -889,35 +889,42 @@
 ommands(
-%7B kernel, markers %7D
+store, handleKernelCommand
 );%0A    %7D
@@ -1192,89 +1192,51 @@
 nds(
-%7B%0A    kernel,%0A    markers%0A  %7D: %7B%0A    kernel: Kernel,%0A    markers: MarkerStore%0A  %7D
+store: Store, handleKernelCommand: Function
 ) %7B%0A
@@ -1277,32 +1277,37 @@
 alListView;%0A    
+if (!
 signalListView =
@@ -1304,24 +1304,27 @@
 ListView
- = new S
+) %7B%0A      s
 ignalLis
@@ -1332,159 +1332,61 @@
 View
-(kernel);%0A    signalListView.onConfirmed = (kernelCommand: %7B command: string %7D) =%3E%0A      this.handleKernelCommand(kernelCommand, %7B kernel, markers %7D
+ = new SignalListView(store, handleKernelCommand
 );%0A
+  
     
@@ -1419,24 +1419,76 @@
 alListView;%0A
+    %7Delse%7B%0A      signalListView.store = store%0A    %7D%0A
     signalLi

refactor kernel to store