   id: 'ladder-team-view'
   template: require 'templates/play/ladder/team'
   startsLoading: true
-  
+
   events:
     'click #rank-button': 'rankSession'
-  
+
   # PART 1: Loading Level/Session
 
   constructor: (options, @levelID, @team) ->


  onLevelLoaded: -> @startLoadingChallengersMaybe()
  onSessionLoaded: -> @startLoadingChallengersMaybe()
  
  # PART 2: Loading some challengers if we don't have any matches yet

  startLoadingChallengersMaybe: ->
    return unless @level.loaded and @session.loaded
    matches = @session.get('matches')
    if matches?.length then @loadNames() else @loadChallengers() 

  loadChallengers: ->
    @challengers = new ChallengersData(@level, @team, @session)
    @challengers.on 'sync', @loadNames, @
    
  # PART 3: Loading the names of the other users
  
  loadNames: ->
    ids = []
    ids.push match.opponents[0].userID for match in @session.get('matches') or []

    ctx.teamID = @team
    ctx.challengers = if not @startsLoading then @getChallengers() else {}
    ctx.readyToRank = @readyToRank()

    convertMatch = (match) ->
      opponent = match.opponent[0]
      state = 'win'
