module JamRuby

  # To use this, be sure to add this in before block: stub_const("APP_CONFIG", web_config)
  class Nav

    def self.home(options ={})
      "#{base_url}/home#{dialog(options)}"
    end

    def self.profile(user)
      "#{base_url}/profile/#{user.id}"
    end

    def self.feed
      "#{base_url}/feed"
    end

    def self.accept_friend_request_dialog(friend_request_id)
      Nav.home(dialog: 'accept-friend-request', dialog_opts: {d1: friend_request_id})
    end

    def self.session_detail(music_session)
      "#{base_url}/account/sessionDetail/#{music_session.id}"
    end

    def self.find_session
      "#{base_url}/findSession"
    end

    def self.session(session)
      "#{base_url}/session/#{session.id}"
    end

    private

    def self.base_url
      "#{APP_CONFIG.external_root_url}/client#"
    end

    def self.dialog(options)
      dialog = ''
      if options[:dialog]
        dialog = "/#{options[:dialog]}"

        if options[:dialog_opts]
          dialog = dialog + '/'

          options[:dialog_opts].each do|key, value|
            dialog = dialog + ERB::Util.url_encode(key) + '=' + ERB::Util.url_encode(value) + '&'
          end

          if options[:dialog_opts].length > 0
            dialog = dialog[0..-2] # trim off trailing '&'
          end
        end
      end

      dialog
    end
  end
end