local module = class("modulePetBoxAttrInfo", G_UIModuleBase)
local petLearningAblityTpl = L_GameTpl:getPetLearningAblityTpl()
local petLearningEnumTpl = L_GameTpl:getPetLearingEnumTpl()
local battleInfoTpl = L_GameTpl:getBattleInfoTpl()

function module:ctor(...)
  module.super.ctor(self, ...)
end

function module.bind()
  return {
    petPropertyList = {
      moduleName = "pages/pet/new/cellNewAttrItem"
    },
    propetyPanel = {
      moduleName = "pages/propertyPanel/modulePropertyPanel"
    }
  }
end

function module.methods()
  return {
    onClick_attrDetail = function(self)
      self:showAttrDetail()
    end
  }
end

function module:created(...)
  module.super.created(self, ...)
end

function module:open()
end

function module:close()
end

function module:setGuid(petGuid)
  local pet = L_PetStore:getPetItem(petGuid)
  self.pet = pet
  local property
  if not math.isEmpty(pet.hero_id) then
    property = L_PetStore:getPetProperty(pet)
  else
    property = L_PetStore:getPetOriginalProperty(pet)
  end
  local topRankComprehension = L_PetStore:getRangeValueComprehension(false, 8, pet.comprehension)
  self.bind.petPropertyList:clear()
  local propertyData = {}
  local all_Attribute = petLearningEnumTpl:getAllEnum(true)
  for i, v in ipairs(all_Attribute) do
    local enumId = petLearningEnumTpl:getEnumNum(v)
    local id = 0
    for n, k in pairs(topRankComprehension) do
      if k.attr_id == enumId then
        id = k.rankId
        break
      end
    end
    local totalVal = L_PetStore:getPetAttFinalValue(property, enumId, petGuid)
    table.insert(propertyData, {
      attrIcon = petLearningEnumTpl:getIcon(petLearningEnumTpl:getTplByEnumId(enumId)),
      value = battleInfoTpl:getShowTxtComma(enumId, totalVal),
      name = petLearningEnumTpl:getName(petLearningEnumTpl:getTplByEnumId(enumId)),
      attrId = id
    })
  end
  self.bind.petPropertyList:insert_array(propertyData)
end

function module:showAttrDetail()
  local pet = self.pet
  self.modules.propetyPanel:initModule({
    petData = pet,
    detailId = L_Const.propertyDetail.kiBo
  })
  self.modules.propetyPanel:setPanelActive(true)
end

return module
