local cls = class("cellPetBattleTagTips", G_UIModuleBase)
local _battleTagTpl = L_GameTpl:getBattleTagTpl()

function cls.bind()
  return {
    color_bg = C_Color(1, 1, 1),
    txt_label = "",
    img_label = "",
    txt_desc = ""
  }
end

function cls:refresh()
  self.cfgId = self.bind.id
  self:initModule()
end

function cls:initModule()
  if not self.cfgId then
    return
  end
  local battleTagCfg = _battleTagTpl:getTplById(self.cfgId)
  local _, color = C_ColorUtility.TryParseHtmlString(_battleTagTpl:getColor(battleTagCfg))
  self.bind.color_bg = color
  self.bind.txt_label = _battleTagTpl:getTitle(battleTagCfg)
  self.bind.img_label = _battleTagTpl:getIcon(battleTagCfg)
  self.bind.txt_desc = _battleTagTpl:getDesc(battleTagCfg)
  self.bindComponents.rectDesc:SetSizeWithCurrentAnchors(1, self.bindComponents.tmpDesc.preferredHeight + 2)
  self:UpdateContainerVerticalLayout(self.bindComponents.rect)
end

function cls:UpdateContainerVerticalLayout(rect)
  Unity.UI.LayoutRebuilder.ForceRebuildLayoutImmediate(rect)
  local height = rect:GetComponent("VerticalLayoutGroup").preferredHeight + 2
  rect:SetSizeWithCurrentAnchors(1, height)
end

return cls
