local this = class("pageCrateTestTeam", G_UIPageBase)

function this.bind()
  return {
    scrollTeam = {
      moduleName = "pages/bugWorld/cellItem/moduleSelectTestTeam"
    },
    scrollPet = {
      moduleName = "pages/bugWorld/cellItem/moduleSelectTestTeam"
    }
  }
end

function this.methods()
  return {
    scrollTeam = {
      onChoice = function(self, index, heroId)
        self:choiceHero(index, heroId)
      end
    },
    scrollPet = {
      onChoice = function(self, index, petId)
        self:choicePet(index, petId)
      end
    },
    onClick_close = function(self)
      L_UI:close(self.pageName)
    end
  }
end

function this:ctor()
  this.super.ctor(self)
end

function this:open(options)
end

function this:close(options)
  this.super.close(self, options)
end

function this:getHeroList()
  local list = {}
  local _heroTpl = L_GameTpl:getHeroTpl()
  local heroDic = _heroTpl.data
  table.insert(list, {
    id = nil,
    txt_name = L_WordsTpl:getValue("ui_moduleQuickRoulette")
  })
  for i, v in pairs(heroDic) do
    if _heroTpl:getIsUsable(v) then
      table.insert(list, {
        id = _heroTpl:getId(v),
        txt_name = _heroTpl:getName(v)
      })
    end
  end
  return list
end

function this:getPetList()
  local list = {}
  local _petInfoTpl = L_GameTpl:getPetTpl()
  local petDic = _petInfoTpl.data
  table.insert(list, {
    id = nil,
    txt_name = L_WordsTpl:getValue("ui_moduleQuickRoulette")
  })
  for i, v in pairs(petDic) do
    local configId = L_GameTpl:getPetTpl():getId(v)
    local name = _petInfoTpl:getName(v)
    table.insert(list, {id = configId, txt_name = name})
  end
  return list
end

function this:choiceHero(index, heroId)
  L_BattleTeamStore:setTeamInfo(index, L_BattleTeamStore:getPetIdByTeamIndex(index), heroId)
end

function this:choicePet(index, petId)
  L_BattleTeamStore:setTeamInfo(index, petId, L_BattleTeamStore:getHeroIdByTeamIndex(index))
end

return this
