local module = class("cellPetTipsGene", G_UIModuleBase)
local petDna = L_GameTpl:getDnaTpl()

function module:ctor(...)
  module.super.ctor(self, ...)
  self.data = {
    id = nil,
    guid = nil,
    rarity = {
      [1] = "UI/Atlas/PetBoxNew/tex_pet_bg_tips_yinzibg1_s.png",
      [2] = "UI/Atlas/PetBoxNew/tex_pet_bg_tips_yinzibg1_s.png",
      [3] = "UI/Atlas/PetBoxNew/tex_pet_bg_tips_yinzibg2_s.png",
      [4] = "UI/Atlas/PetBoxNew/tex_pet_bg_tips_yinzibg3_s.png",
      [5] = "",
      [6] = "UI/Atlas/PetBoxNew/tex_pet_bg_tips_yinzibg5.png"
    }
  }
end

function module.bind()
  return {
    bg = "",
    show_lockBg = false,
    active_specialLevel = false,
    active_levelList = false,
    levelList = {
      moduleName = "pages/Pet/cellDotStarItem"
    },
    active_line = true,
    active_debuffLine = false,
    geneNameText = "",
    show_rarity = false,
    lock_color = C_Color.white,
    color_line = C_Color(1, 1, 1, 0.3),
    showLockInfo = false,
    lockInfo = "",
    geneDescText = ""
  }
end

function module.methods()
  return {}
end

function module:refresh()
  self:refreshInfo()
end

function module:refreshInfo()
  self.bind.geneNameText = self.bind.skillName
  if not math.isEmpty(self.bind.geneId) then
    local isSpecialGene = self.bind.rarity >= #self.data.rarity
    local isTopGene = self.bind.rarity == #self.data.rarity - 1
    self.bind.show_rarity = isTopGene
    self.bind.bg = self.data.rarity[self.bind.rarity]
    if isSpecialGene then
      self.bind.geneNameText = string.format("<color=#4c5e87>%s</color>", self.bind.skillName)
      self.bind.lock_color = C_Color(0.3, 0.369, 0.53, 0.5)
      self.bind.active_line = true
      self.bind.active_debuffLine = false
    elseif isTopGene then
      self.bind.geneNameText = string.format("<color=#FFD65B>%s</color>", self.bind.skillName)
      self.bind.lock_color = C_Color(0.9843137, 0.8666667, 0.5843138, 0.7)
    else
      self.bind.geneNameText = string.format("<color=#FFFFFF>%s</color>", self.bind.skillName)
      self.bind.lock_color = C_Color(1, 1, 1, 0.7)
    end
    if isSpecialGene then
      self.bind.color_line = C_Color(0.7, 0.9, 0.97, 0.3)
    else
      self.bind.color_line = C_Color(1, 1, 1, 0.3)
    end
    self.bind.active_levelList = not isSpecialGene
    self.bind.active_specialLevel = isSpecialGene
    if not isSpecialGene then
      self.bind.levelList:clear()
      self.star = self.bind.rarity - 2
      if self.star > 0 then
        local data = {}
        for i = 1, self.star do
          table.insert(data, {})
        end
        self.bind.levelList:insert_array(data)
        self.bind.active_line = true
        self.bind.active_debuffLine = false
      else
        self.bind.active_line = false
        self.bind.active_debuffLine = true
      end
    end
  end
  self.bind.geneDescText = self.bind.describe
  self.bind.showLockInfo = self.bind.show_lockBg
  local unlockList = L_PetManager:getGeneUnlockConditions()
  if self.bind.showLockInfo == true then
    self.bind.lockInfo = L_WordsTpl:getValue("ui_moduleCanteenFree_03", {
      [0] = unlockList[self.bind.genePos]
    })
  end
end

return module
