local this = class("pageSpiritronStrengthSuccess", G_UIPageBase)
local battleInfoTpl = L_GameTpl:getBattleInfoTpl()
local attrBaseName = {
  [L_Const.battleAtt.MAXHP] = "info_attr_basic_hp",
  [L_Const.battleAtt.ATK] = "info_attr_basic_atk",
  [L_Const.battleAtt.DEF] = "info_attr_basic_def",
  [L_Const.battleAtt.MDEF] = "info_attr_basic_mdef"
}

function this.bind()
  return {
    txt_spiritLevel = "",
    list_spiritAtt = {
      moduleName = "pages/HeroPanel/hero/heroProperty"
    }
  }
end

function this.methods()
  return {
    onClick_closeUpStarSucceed = function(self)
      if self.callback then
        self.callback()
      end
      L_UI:close(self.pageName)
    end
  }
end

function this:preOpen(options)
  self.guid = options and options.guid or 0
  self.curPropertyList = options.curPropertyList
  self.describe = options and options.describe or ""
  self.callback = options and options.callback
  self:levelUpSucceed()
end

function this:levelUpSucceed()
  local spData = L_SpiritronStore:getSpiritronItem(self.guid)
  self.bind.txt_spiritLevel = tostring(spData.spiritronLv)
  local afterPropertyList = L_SpiritronManager:getConfigAttList(spData.spiritronId, spData.spiritronLv, spData.rank)
  local propertyData = {}
  for k, v in pairs(afterPropertyList) do
    local currStr = battleInfoTpl:getShowPropertyTxt_spiritron(k, self.curPropertyList[k])
    local nextStr = battleInfoTpl:getShowTxtComma(k, afterPropertyList[k])
    printf("currStr:" .. currStr)
    local tpl_battleInfo = battleInfoTpl:getTplById(k)
    local attIcon = battleInfoTpl:getIcon(tpl_battleInfo)
    local strName = L_WordsTpl:getValue(attrBaseName[k])
    local name = string.isEmpty(strName) and battleInfoTpl:getName(tpl_battleInfo) or strName
    table.insert(propertyData, {
      toggle_state = false,
      curAttr = currStr,
      nextAttr = nextStr,
      name = name,
      icon = attIcon,
      active_icon = true,
      id = k
    })
  end
  L_SpiritronManager:sortAttrId(propertyData)
  for i = 1, #propertyData do
    local bgBool = false
    if math.floor(i % 2) > 0 then
      bgBool = true
    end
    propertyData[i].toggle_state = not bgBool
  end
  self.bind.list_spiritAtt:clear()
  self.bind.list_spiritAtt:insert_array(propertyData)
end

return this
