$ = jQuery
context = window
logger = context.JK.logger
rest = new context.JK.Rest()

@NavStore = Reflux.createStore(
  {

    screenPath: null
    currentSection: null
    currentScreenName: null

    sections: {jamclass: {name: 'JamClass Home', url: '/client#/jamclass'}, jamtrack: {name: 'JamTrack Home', url: '/client#/jamtrack'}}

    listenables: @NavActions

    init: ->
      this.listenTo(context.AppStore, this.onAppInit)

    onAppInit: (@app) ->

    onScreenChanged: (screenPath, screenName) ->
      if screenPath == @screenPath
        return

      @screenPath = screenPath
      @currentScreenName = screenName
      @currentSection = null
      if screenPath?
        index = screenPath.indexOf('/')
        if index > -1
          rootPath = screenPath.substring(0, index)
        else
          rootPath = screenPath
        @currentSection = @sections[rootPath]

      @changed()

    onSetScreenInfo: (currentScreenName) ->
      @currentScreenName = currentScreenName
      @changed()

    changed:() ->
      @trigger({screenPath: @screenPath, currentScreen: @currentScreen, currentSection: @currentSection, currentScreenName: @currentScreenName})
  }
)
