local this = class("moduleFormationPetProperty", G_UIModuleBase)
local petLearningEnumTpl = L_GameTpl:getPetLearingEnumTpl()
local battleInfoTpl = L_GameTpl:getBattleInfoTpl()
local petGradeTpl = L_GameTpl:getPetGradeTpl()

function this.bind()
  return {
    go_content = false,
    modulePetBoxRating = {
      moduleName = "pages/pet/new/modulePetBoxRating"
    },
    txt_petFavorLv = "",
    list_attribute = {
      moduleName = "pages/pet/cellAttrItem"
    },
    list_cellSkillItem = {
      moduleName = "pages/pet/new/cellPetNewSkill"
    },
    list_cellPetGene = {
      moduleName = "pages/pet/new/cellPetNewGene"
    },
    arrowActive = true,
    txt_petName = ""
  }
end

function this.methods()
  return {}
end

function this:Init(data)
  self.bind.go_content = data.isShow
  self.bind.arrowActive = data.arrowActive
  self:initInfo(data.guid)
end

function this:initInfo(guid)
  local pet = L_PetStore:getPetItem(guid)
  local property = L_PetStore:getPetOriginalProperty(pet)
  self.bind.txt_petName = pet:getPetName()
  self.modules.modulePetBoxRating:setGuid(guid)
  local list = L_PetStore:getPetSkills(pet, false, false, true)
  for i, v in pairs(list) do
    v.skillLv = string.gsub(v.skillLv, "Lv.", "")
  end
  self.bind.list_cellSkillItem:clear()
  self.bind.list_cellSkillItem:insert_array(list)
  local topRankComprehension = L_PetStore:getRangeValueComprehension(false, 8, pet.comprehension)
  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
    table.insert(propertyData, {
      attrIcon = petLearningEnumTpl:getIcon(petLearningEnumTpl:getTplByEnumId(enumId)),
      value = battleInfoTpl:getShowTxtComma(enumId, L_PetStore:getPetAttFinalValue(property, enumId, guid)),
      name = petLearningEnumTpl:getName(petLearningEnumTpl:getTplByEnumId(enumId)),
      attrId = id
    })
  end
  self.bind.list_attribute:clear()
  self.bind.list_attribute:insert_array(propertyData)
  local genelist = L_PetStore:getPetSkills(pet, true, true, false)
  table.sort(genelist, function(a, b)
    return a.genePos < b.genePos
  end)
  for k, gene in ipairs(genelist) do
    gene.index = k
  end
  self.bind.list_cellPetGene:clear()
  self.bind.list_cellPetGene:insert_array(genelist)
  self.bind.txt_petFavorLv = tostring(pet:petFavorLv())
end

function this:showModuleInfo(isShow, guid)
  self.bind.go_content = isShow
  if isShow then
    self:initInfo(guid)
  end
end

function this:getArrowContentRect()
  return self.bindComponents.rect_bg
end

return this
