local this = class("modulePetNewSimpleTags", G_UIModuleBase)
local petInfoTpl = L_GameTpl:getPetTpl()
local modulePetBattleTagTips_Path = "UI/Pages/PetBox/modulePetBattleTagTips.prefab"
local modulePetBattleTagTips = "ui.pages.pet.new.modulePetBattleTagTips"

function this.bind()
  return {
    list_element = {
      moduleName = "pages/Pet/cellPetElement"
    },
    list_capacity = {
      moduleName = "pages/Pet/cellTagItem"
    },
    active_special_obj = false,
    active_flashTag = false
  }
end

function this:setGuid(guid, bShowTips)
  self.pet = L_PetStore:getPetItem(guid)
  self:refreshModule(self.pet.id, bShowTips)
  self.bind.active_special_obj = self.pet:isSpecialPet() and self.pet:isSpecialPet() > 0
  self.bind.active_flashTag = self.pet:hasFlashGene()
end

function this:setConfigId(configId, bShowTips, params)
  self:refreshModule(configId, bShowTips, params)
end

function this:refreshModule(configId, bShowTips, params)
  local petTpl = petInfoTpl:getTplById(configId)
  local elementData = {}
  local element = petInfoTpl:getElement(petTpl)
  for _, v in ipairs(element) do
    table.insert(elementData, {element = v, allElement = element})
  end
  self.bind.list_element:clear()
  self.bind.list_element:insert_array(elementData)
  local onBtnTagCell
  if params then
    function onBtnTagCell()
      L_UI:open("pageTipBubble", {
        data = {
          modulePetBattleTagTips_Path,
          
          modulePetBattleTagTips,
          configId,
          self.bindComponents.rectTagList,
          params.pointTo,
          true,
          1,
          params.borderDistance,
          params.transSize
        }
      })
    end
  else
    function onBtnTagCell()
      L_UI:open("pageTipBubble", {
        data = {
          modulePetBattleTagTips_Path,
          
          modulePetBattleTagTips,
          configId,
          self.bindComponents.rectTagList,
          0,
          true,
          1,
          C_Vector2(30, 27),
          C_Vector2(10, 10)
        }
      })
    end
  end
  local simpleTagData = {}
  local battleTag = petInfoTpl:getBattleTag(petTpl)
  if battleTag then
    for _, id in ipairs(battleTag) do
      table.insert(simpleTagData, {
        id = id,
        cbk = bShowTips and onBtnTagCell or nil
      })
    end
  end
  self.bind.list_capacity:clear()
  self.bind.list_capacity:insert_array(simpleTagData)
  Unity.UI.LayoutRebuilder.ForceRebuildLayoutImmediate(self.bindComponents.rectTagList)
end

return this
