+debug = require('debug')('sidebar:controller')
 kd = require 'kd'
 EnvironmentFlux = require 'app/flux/environment'
 remote = require 'app/remote'



  setVisibility: (type, id, state) ->
    fetchVisibility()
      .then (filters) =>
        filters[type][id] = state
        return filters



    new Promise (resolve) ->
      appStorageController.storage('Sidebar')

          resolve filters


  addManaged: (id) ->

    debug 'add managed vm', { id }

    @managed[id] = id
    @emit 'change'


  removeManaged: (id) ->

    debug 'remove managed vm', { id }

    delete @managed[id]
    @emit 'change'


  getManaged: ->

    first = Object.keys(@managed)?.first

    if first then first else null


  getState: (selector = identity) ->
    return selector {
      selected: @selected
      leavingId: @leavingId
      invitedId: @invitedId
      managedId: @getManaged()
    }


