local this = class("modulePetAttributeInfo", G_UIModuleBase)
local _petLearingEnumTpl = L_GameTpl:getPetLearingEnumTpl()
local _petFeedItemTpl = L_GameTpl:getPetFeedItemTpl()

function this.bind()
  return {
    list_cellPetAttributeInfo = {
      moduleName = "pages/pet/cellPetAttributeInfo"
    }
  }
end

function this.methods()
  return {}
end

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

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

function this:setShowPetGuid(petGuid)
  self.petGuid = petGuid
end

function this:refreshUI()
  if self.petGuid == nil then
    errorf("modulePetAttributeInfo \230\156\170\232\174\190\231\189\174\233\156\128\232\166\129\229\177\149\231\164\186\231\154\132\229\174\160\231\137\169Guid")
    return
  end
  local cellPetAttributeInfoList = {}
  local petLearingEnumTplData = _petLearingEnumTpl:getAllEnum(true)
  for i = 1, 4 do
    table.insert(cellPetAttributeInfoList, {})
  end
  self.bind.list_cellPetAttributeInfo:clear()
  self.bind.list_cellPetAttributeInfo:insert_array(cellPetAttributeInfoList)
  for i = 1, #self.bind.list_cellPetAttributeInfo do
    local cellPetAttributeInfo = self.bind.list_cellPetAttributeInfo:getItemCls(i)
    local petLearingEnumTpl = _petLearingEnumTpl:getTplById(i)
    local attrEnumNum = _petLearingEnumTpl:getEnumNum(petLearingEnumTpl)
    cellPetAttributeInfo:setShowPetGuidAndAttrEnumNum(self.petGuid, attrEnumNum)
    cellPetAttributeInfo:refreshBaseInfoUI()
  end
end

function this:refreshPreAddComprehensionExpUI(preUseFruitInfoList, curLv)
  local addComprehensionExpList = {}
  local petLearingEnumTplData = _petLearingEnumTpl:getAllEnum(true)
  for _, petLearingEnumTpl in pairs(petLearingEnumTplData) do
    local attrEnumNum = _petLearingEnumTpl:getEnumNum(petLearingEnumTpl)
    addComprehensionExpList[attrEnumNum] = 0
  end
  for _, preUseFruitInfo in pairs(preUseFruitInfoList) do
    local itemId = preUseFruitInfo.itemId
    local itemNum = preUseFruitInfo.itemNum
    local petFeedItemTpl = _petFeedItemTpl:getTplById(itemId)
    local effectParamList = _petFeedItemTpl:getEffectParamList(petFeedItemTpl)
    for _, effectParam in pairs(effectParamList) do
      local attrEnumNum = effectParam[1]
      local expAddNum = effectParam[2] * itemNum
      addComprehensionExpList[attrEnumNum] = addComprehensionExpList[attrEnumNum] + expAddNum
    end
  end
  for i = 1, #self.bind.list_cellPetAttributeInfo do
    local cellPetAttributeInfo = self.bind.list_cellPetAttributeInfo:getItemCls(i)
    local attrEnumNum = cellPetAttributeInfo:getAttrEnumNum()
    local addExp = addComprehensionExpList[attrEnumNum]
    cellPetAttributeInfo:refreshPreAddComprehensionExpUI(addExp, curLv)
  end
end

function this:close()
end

return this
