local this = class("pageHeroTalentInfo", G_UIPageBase)
local talentRuneTpl = L_GameTpl:getTalentRuneTpl()

function this.bind()
  return {
    runeTypeText = "",
    runeIcon = "",
    bg_runeTypeText = "",
    moduleTalentContentActive = true,
    moduleTalentContentSkillActive = false,
    moduleCurrency = {
      moduleName = "modulePages/moduleCurrency"
    },
    moduleTalentContent = {
      moduleName = "pages/HeroPanel/talent/moduleTalentContent"
    },
    moduleTalentContentSkill = {
      moduleName = "pages/HeroPanel/talent/moduleTalentContent"
    }
  }
end

function this.methods()
  return {
    onClick_close = function(self)
      if not L_UI:checkPageOpen("pageHeroTalentInfo") then
        return
      end
      L_UI:close(self.pageName)
    end
  }
end

function this:preOpen(options)
  this.super.preOpen(self, options)
  L_BagStore:listenCallFunc(L_BagStore.event.refreshBag, self.onEvent_composeSuccess, self)
  self.options = options
  self:initPage()
end

function this:close(options)
  L_BagStore:unListenCallFunc(L_BagStore.event.refreshBag, self.onEvent_composeSuccess, self)
end

function this:onEvent_composeSuccess()
  self:initPage()
end

function this:initPage()
  local runeTpl = talentRuneTpl:getTplById(self.options.runeId)
  local itemId = talentRuneTpl:getRuneItem(runeTpl)
  local item = L_ItemTplManager:getCommonItem(itemId)
  self.bind.runeIcon = item.icon
  self.isLackRune = L_BagStore:getItemNum(itemId) <= 0
  local runeSkills = talentRuneTpl:getRuneSkill(runeTpl)
  local hasSkill = 0 < #runeSkills
  self.bind.moduleTalentContentActive = not hasSkill
  self.bind.moduleTalentContentSkillActive = hasSkill
  if self.bind.moduleTalentContentActive then
    self.modules.moduleTalentContent:initPage(table.clone(self.options))
  end
  if self.bind.moduleTalentContentSkillActive then
    self.modules.moduleTalentContentSkill:initPage(table.clone(self.options))
  end
  self.bind.runeTypeText = talentRuneTpl:getRuneTypeName(runeTpl)
  self.bind.bg_runeTypeText = talentRuneTpl:getRuneTypeEngName(runeTpl)
  local tpl_sys = L_GameTpl:getSystemUnlockTpl():getTplById(L_SystemConst.enum.heroTalent)
  self.modules.moduleCurrency:refreshRes(tpl_sys)
end

return this
