$ = jQuery
context = window
logger = context.JK.logger

ProfileActions = @ProfileActions

@ProfileStore = Reflux.createStore(
  {
    listenables: ProfileActions

    customBack: null
    customBackDisplay: null
    returnNav: null
    solo: false

    # step can be:
    # introduction
    # basics
    # pricing
    # experience
    onStartProfileEdit: (step, solo) ->

      if !step?
        step = ''

      if step != '' && step != 'samples' && step != 'interests' && step != 'experience'
        alert("invalid step: " + step)
        return

      @solo = solo
      @returnNav = window.location.href

      window.location = '/client#/account/profile/' + step

    onDoneProfileEdit: () ->

      if @returnNav
        window.location = @returnNav
        @returnNav = null
      else
        window.location = "/client#/profile/" + context.JK.currentUserId;

      @solo = false

    onCancelProfileEdit: () ->

      if @returnNav
        window.location = @returnNav
        @returnNav = null
      else
        window.location = '/client#/profile/' + context.JK.currentUserId
      @solo = false

    onStartTeacherEdit: (step, solo) ->

      if !step?
        step = 'introduction'

      if step != 'introduction' && step != 'basics' && step != 'pricing' && step != 'experience'
        alert("invalid step: " + step)
        return

      @solo = solo
      @returnNav = window.location.href

      window.location = '/client#/teachers/setup/' + step

    onDoneTeacherEdit: () ->

      if @solo
        if @returnNav
          window.location = @returnNav
          @returnNav = null
        else
          window.location = '/client#/home'

      @solo = false

    onCancelTeacherEdit: () ->

      if @returnNav
        window.location = @returnNav
        @returnNav = null
      else
        window.location = '/client#/home'

      @solo = false

    onEditProfileNext: (step) ->

      if @solo
        if @returnNav
          window.location = @returnNav
          @returnNav = null
        else
          window.location = '/client#/home'
        @solo = false
      else
        context.location = "/client#/account/profile/" + step

    onViewTeacherProfile: (user, customBack, customBackDisplay) ->

      @customBack = customBack
      @customBackDisplay = customBackDisplay
      context.location = "/client#/profile/teacher/#{user.id}"

    onViewTeacherProfileDone: () ->
      @customBack = null
      @customBackDisplay = null
  }
)


