local module = class("moduleHeroTalent", require("ui.pages.HeroPanel.moduleHeroBase"))
local giftPath = "UI/UIEffect/TalentRing/pre_uipage_giftring.prefab"
local talentRankTpl = L_GameTpl:getTalentRankTpl()
local talentRuneTpl = L_GameTpl:getTalentRuneTpl()
local runePositions = {
  runePosition_6 = {
    rune1 = C_Vector2(-292, -28),
    rune2 = C_Vector2(-152, 148),
    rune3 = C_Vector2(-42, -114),
    rune4 = C_Vector2(82, 76),
    rune5 = C_Vector2(220, -70),
    rune6 = C_Vector2(344, 152)
  },
  runePosition_5 = {
    rune1 = C_Vector2(-261, 129),
    rune2 = C_Vector2(-127, -24),
    rune3 = C_Vector2(26, 172),
    rune4 = C_Vector2(166, -111),
    rune5 = C_Vector2(287, 81)
  },
  runePosition_4 = {
    rune1 = C_Vector2(-228, 86),
    rune2 = C_Vector2(-60, -24),
    rune3 = C_Vector2(111, 143),
    rune4 = C_Vector2(284, 8)
  },
  runePosition_3 = {
    rune1 = C_Vector2(-153, -71),
    rune2 = C_Vector2(24, 149),
    rune3 = C_Vector2(220, 12)
  }
}
local rankImgPath = "UI/Atlas/HeroTalentRankNum/tex_role_talent_bg_numA%s.png"

function module.bind()
  return {
    isShowCurrency = false,
    moduleCurrency = {
      moduleName = "modulePages/moduleCurrency"
    },
    breakBtnActive = false,
    equipBtnActive = false,
    talentRuneList = {
      moduleName = "pages/HeroPanel/talent/cellTalentRuneItem"
    },
    maxNodeActive = false,
    equipNodeActive = false,
    equipBtn = L_Const.ModuleInfo.ModuleBtn,
    breakBtn = L_Const.ModuleInfo.ModuleBtn,
    txt_title = "",
    curRank = "",
    unlockDesAcitve = false,
    unlockDes = "",
    moduleTalentDetail = {
      moduleName = "pages/HeroPanel/talent/moduleTalentDetail"
    },
    talentDetailActive = false,
    rankStatusText = "",
    backCurrentBtn = L_Const.ModuleInfo.ModuleBtn,
    backCurrentBtnActive = false,
    active_nextRankBtn = true,
    active_previousRankBtn = true
  }
end

function module.methods()
  return {
    onClick_detailBtn = function(self)
      self.bind.talentDetailActive = not self.bind.talentDetailActive
    end,
    onClick_nextBtn = function(self)
      local hero = self:getHero(self.heroGuid)
      local maxRank = talentRankTpl:getHeroMaxRankNum(L_HeroStore:getHeroConfigId(hero))
      if maxRank <= self.currentRank then
        return
      end
      self.currentRank = self.currentRank + 1
      self:switchRank(nil, true)
      self.giftRingAnim:SetTrigger("SwitchNext")
      self.bindComponents.heroTalentAnim:SetTrigger("Next")
    end,
    onClick_previousBtn = function(self)
      if self.currentRank <= 1 then
        return
      end
      self.currentRank = self.currentRank - 1
      self:switchRank(nil, true)
      self.giftRingAnim:SetTrigger("SwitchLast")
      self.bindComponents.heroTalentAnim:SetTrigger("Last")
    end,
    onClick_rankLimitBtn = function(self)
      local hero = self:getHero(self.heroGuid)
      L_HeroManager:showHeroSelection(L_Const.heroModuleType.Property, L_HeroStore:getHeroGuid(hero), {openLevelUp = true})
    end,
    onClick_previewRankRewards = function(self)
      local hero = self:getHero(self.heroGuid)
      local data = talentRankRewardTpl:getSortedData()
      local idx = 1
      for i, reward in ipairs(data) do
        local rank = reward.level
        if not L_HeroStore:IsRankRewardGetted(hero, rank) then
          idx = reward.id
          break
        end
      end
      L_UI:open("pageHeroRankRewardPreview", {
        index = idx,
        heroId = self.heroGuid
      })
    end,
    moduleTalentDetail = {
      onClick_empty = function(self)
        self.bind.talentDetailActive = false
      end
    }
  }
end

function module:open()
  self._ESyncHeroServerDataHandler = handler(self, self.onEvent_refreshHero)
  L_BagStore:listenCallFunc(L_BagStore.event.refreshBag, self.onEvent_refreshBag, self)
  L_PlayerStore:listenCallFunc(L_PlayerStore.event.refreshAttr, self.onEvent_refreshBag, self)
  AzurWorld.heroMgr:RegisterEvent(C_EHeroEvent.ESyncHeroServerData, self._ESyncHeroServerDataHandler)
end

function module:show()
  self.giftRing = C_LuaUtility.InstantiateAsync(giftPath, function(go)
    if not L_CommonUtil.isValid(go) then
      errorf("cant load asset from " .. giftPath)
      return
    end
    L_AudioUtil.playSound("Play_SFX_System_UI_StarGift_Enter")
    self.giftRingAnim = go.transform:GetChild(0):GetComponent(typeof(C_CsAnimator))
    L_UI:open("pageBlank", {timeClose = 0.5})
    self.giftRingAnim:SetTrigger("In")
    Timer.once(0.483, function()
      if not self.params or self.params.forceRefesh then
        self:initPage({isBreak = false, forceRefesh = true})
      end
    end)
  end, C_CameraManager.mainCamera.transform)
end

function module:hide()
  if self.giftRing then
    C_LuaUtility.DestroyObject(self.giftRing)
  end
  self.params = nil
end

function module:close()
  if self.giftRing then
    C_LuaUtility.DestroyObject(self.giftRing)
  end
  if self.runeEquipSuccessTimer ~= nil then
    Timer.remove(self.runeEquipSuccessTimer)
  end
  AzurWorld.heroMgr:UnregisterEvent(C_EHeroEvent.ESyncHeroServerData, self._ESyncHeroServerDataHandler)
  L_PlayerStore:unListenCallFunc(L_PlayerStore.event.refreshAttr, self.onEvent_refreshBag, self)
  L_BagStore:unListenCallFunc(L_BagStore.event.refreshBag, self.onEvent_refreshBag, self)
end

function module:onEvent_refreshBag()
  self:refreshBtnsStatus(self.hero, self.rankBreakItems)
end

function module:onEvent_refreshHero(enum, varList)
  local hero = varList:GetObject(0)
  if L_HeroStore:getHeroGuid(hero) ~= self.heroGuid then
    self.bind.talentDetailActive = false
    return
  end
  self:initPage({
    isBreak = self.isBreak,
    isHeroRefresh = true
  })
end

function module:onBreakBtnClicked()
  if self.isBreak then
    return
  end
  if L_BattleDataManager:checkPlayerBattle() then
    L_FlyMsgManager:showNormalMsg(L_BattleDataManager:getBattleBlockTips(L_Const.BattleBlockType.HeroRuneUpgrade))
    return
  end
  if self.isLackBreakGold then
    L_FlyMsgManager:showNormalMsg(L_WordsTpl:getValue("ui_hero_rune_break_lack_gold"))
    return
  end
  self.isBreak = true
  AzurWorld.heroMgr:ReqUpgradeHeroRune(self.heroGuid, function(errCode, rspData)
    local options = {
      isRankUp = true,
      heroGuid = self.heroGuid,
      serverResp = rspData
    }
    self.runeEquipSuccessTimer = Timer.once(self.protectTime * 2 + 1.6, function()
      L_UI:open("pageHeroRuneEquipedSuccess", options, function()
        self.isBreak = false
      end)
    end)
    L_AudioUtil.playSound("Play_SFX_System_UI_StarGift_LevelUp")
  end)
end

function module:autoEquipRune()
  if self.isBreak then
    return
  end
  if L_BattleDataManager:checkPlayerBattle() then
    L_FlyMsgManager:showNormalMsg(L_BattleDataManager:getBattleBlockTips(L_Const.BattleBlockType.HeroRuneEquip))
    return
  end
  local slots = {}
  local runes = {}
  local isLackRune = true
  for _, rune in ipairs(self.runeData) do
    if not rune.isEquiped then
      local runeTpl = talentRuneTpl:getTplById(rune.runeId)
      local itemId = talentRuneTpl:getRuneItem(runeTpl)
      if L_BagStore:getItemNum(itemId) > 0 then
        table.insert(slots, rune.slotId)
        table.insert(runes, rune.runeId)
        isLackRune = false
      end
    end
  end
  if isLackRune and self.isLackEquipGold then
    L_FlyMsgManager:showNormalMsg(L_WordsTpl:getValue("ui_hero_rune_lack_resource"))
    return
  end
  if isLackRune then
    L_FlyMsgManager:showNormalMsg(L_WordsTpl:getValue("ui_hero_rune_lack_equip"))
    return
  end
  if self.isLackEquipGold then
    L_FlyMsgManager:showNormalMsg(L_WordsTpl:getValue("ui_hero_rune_lack_gold"))
    return
  end
  self.isBreak = true
  L_UI:open("pageAutoRuneConfirm", {
    confirmCallback = function()
      AzurWorld.heroMgr:ReqHeroRuneEquip(self.heroGuid, slots, function(errCode, rspData)
        Timer.once(self.protectTime + 1.2, function()
          self.isBreak = false
        end)
        L_AudioUtil.playSound("Play_SFX_System_UI_StarGift_Equip")
      end)
    end,
    cancelCallback = function()
      self.isBreak = false
    end,
    runes = runes,
    heroGuid = self.heroGuid,
    txtTitle = L_WordsTpl:getValue("ui_hero_rune_quick_equip"),
    hideConfirm = true
  })
end

function module:switchRank(jumpRuneId, isLocation)
  local hero = self:getHero(self.heroGuid)
  if L_HeroStore:getHeroRank(hero) == self.currentRank and isLocation then
    L_UI:open("pageBlank", {timeClose = 0.5})
    self:initPage({isBreak = false, forceRefesh = true})
    return
  end
  L_UI:open("pageBlank", {timeClose = 0.5})
  self:rankViewChange()
  if self.currentRank > L_HeroStore:getHeroRank(hero) then
    self.bind.rankStatusText = L_WordsTpl:getValue("ui_talent_detail_title_yulan")
  else
    self.bind.rankStatusText = L_WordsTpl:getValue("ui_talent_detail_title_yilinjie")
  end
  self:refreshCurRankImg()
  local rankTpl = talentRankTpl:getHeroRankTpl(L_HeroStore:getHeroConfigId(hero), self.currentRank)
  local rankBreakItems = talentRankTpl:getRankBreakthroughItem(rankTpl)
  local runeData = {}
  local runePosition = runePositions["runePosition_" .. tostring(#rankBreakItems)]
  for k, id in ipairs(rankBreakItems) do
    local tmp = {
      runeId = id,
      isEquiped = self.currentRank < L_HeroStore:getHeroRank(hero),
      heroGuid = self.heroGuid,
      slotId = k - 1,
      runePosition = runePosition["rune" .. k],
      isPreview = true,
      curRank = self.currentRank
    }
    table.insert(runeData, tmp)
  end
  for _, v in ipairs(runeData) do
    v.isInit = true
  end
  self.bind.talentRuneList:clear()
  self.bind.talentRuneList:insert_array(runeData)
  if L_HeroStore:getHeroRank(hero) == self.currentRank then
    self.runeData = runeData
  end
  for i = 1, #self.bind.talentRuneList do
    self.bind.talentRuneList:getItemCls(i):cellPlayAnim(true, "Show", 0, i * 0.066)
  end
  self.bindComponents.heroTalentAnim:SetTrigger("Show")
  self:refreshBtnsStatus(hero, rankBreakItems)
end

function module:initPage(params)
  self.params = params
  self.heroGuid = self:getModeController():getSelectGuid()
  self.canClose = true
  self.bind.rankStatusText = L_WordsTpl:getValue("ui_talent_title_current")
  self.bind.txt_title = L_WordsTpl:getValue("ui_talent_rank_title")
  local hero = self:getHero(self.heroGuid)
  if params and not math.isEmpty(params.jumpRank) then
    self.currentRank = params.jumpRank
  else
    self.currentRank = L_HeroStore:getHeroRank(hero)
  end
  self:rankViewChange()
  if params and params.forceRefesh then
    self:refreshRuneList(nil, true)
  elseif params and not math.isEmpty(params.jumpRank) then
    self:refreshRuneList(nil, true)
  elseif self.lastHeroId == self.heroGuid and (params == nil or not params.isBreak) then
    self:changeRuneList()
  elseif self.lastHeroId ~= self.heroGuid and self.lastHeroId ~= nil and (params == nil or not params.isHeroRefresh) then
    self:refreshRuneList(nil, nil, true)
  elseif self.lastHeroId == nil then
    self:refreshRuneList()
  end
  if params ~= nil and params.isBreak then
    Timer.once(0.1, function()
      self:refreshRuneList(true)
    end, self)
  end
  self.lastHeroId = self.heroGuid
  self.modules.moduleTalentDetail:initModule({
    heroConfigId = L_HeroStore:getHeroConfigId(hero),
    rank = L_HeroStore:getHeroRank(hero),
    runes = L_HeroStore:getHeroRuneIds(hero) or {}
  })
end

function module:closePage()
  C_LuaUtility.DestroyObject(self.giftRing)
  self.bind.talentDetailActive = false
  self.currentRank = nil
end

function module:refreshRuneList(isBreak, isForceRefresh, isHeroRefresh)
  self.protectTime = 0
  local hero = self:getHero(self.heroGuid)
  local rankTpl = talentRankTpl:getHeroRankTpl(L_HeroStore:getHeroConfigId(hero), self.currentRank)
  local rankBreakItems = talentRankTpl:getRankBreakthroughItem(rankTpl)
  local runes = L_HeroStore:getHeroRuneIds(hero)
  self.runeData = {}
  self.slotEquiped = {}
  self.allEquiped = true
  local runePosition = runePositions["runePosition_" .. tostring(#rankBreakItems)]
  for k, id in ipairs(rankBreakItems) do
    local tmp = {
      runeId = id,
      isEquiped = self.currentRank <= hero.heroRank and not math.isEmpty(runes[k]),
      heroGuid = self.heroGuid,
      slotId = k - 1,
      runePosition = runePosition["rune" .. k],
      isPreview = self.currentRank > hero.heroRank,
      curRank = self.currentRank
    }
    table.insert(self.runeData, tmp)
    if not tmp.isEquiped then
      self.allEquiped = false
    end
  end
  if isBreak then
    self:setCanClose(true)
    if self.lastTalentRuneNums < #rankBreakItems then
      for i = 1, #self.bind.talentRuneList do
        self.bind.talentRuneList:getItemCls(i):cellPlayAnim(false, "Up", 0, i * 0.066)
        self.protectTime = i * 0.066
      end
      self.protectTime = self.protectTime * 2 + 0.066
      Timer.once(0.8, function()
        self.bind.talentRuneList:insert(#rankBreakItems, {})
        for i = 1, #self.bind.talentRuneList do
          self.bind.talentRuneList:change(i, self.runeData[i])
          self.bind.talentRuneList:getItemCls(i):cellPlayAnim(true, "Show", 0, i * 0.066)
        end
      end, self)
    elseif self.lastTalentRuneNums == #rankBreakItems then
      for i = 1, #self.bind.talentRuneList do
        self.bind.talentRuneList:getItemCls(i):cellPlayAnim(false, "Up", 0, i * 0.066)
        self.protectTime = i * 0.066
      end
      self.protectTime = self.protectTime * 2
      Timer.once(0.8, function()
        for i = 1, #self.bind.talentRuneList do
          self.bind.talentRuneList:change(i, self.runeData[i])
          self.bind.talentRuneList:getItemCls(i):cellPlayAnim(true, "Show", 0, i * 0.066)
        end
      end, self)
    else
      for i = 1, #self.bind.talentRuneList do
        self.bind.talentRuneList:getItemCls(i):cellPlayAnim(false, "Up", 0, i * 0.066)
        self.protectTime = i * 0.066
      end
      self.protectTime = self.protectTime * 2 - 0.066
      Timer.once(0.8, function()
        for i = #self.bind.talentRuneList, #rankBreakItems, -1 do
          self.bind.talentRuneList:remove(i)
        end
        for i = 1, #self.bind.talentRuneList do
          self.bind.talentRuneList:change(i, self.runeData[i])
          self.bind.talentRuneList:getItemCls(i):cellPlayAnim(true, "Show", 0, i * 0.066)
        end
      end, self)
    end
    Timer.once(0.43333, function()
      self.giftRingAnim:SetTrigger("Upgrade")
    end, self)
    Timer.once(0.5167, function()
      self.bindComponents.heroTalentAnim:SetTrigger("Upgrade")
    end, self)
    Timer.once(0.6817, function()
      self:refreshCurRankImg()
    end, self)
    Timer.once(self.protectTime + 1.6, function()
      self:setCanClose(false)
    end, self)
  elseif isForceRefresh then
    for _, v in ipairs(self.runeData) do
      v.isInit = true
    end
    self.bind.talentRuneList:clear()
    self.bind.talentRuneList:insert_array(self.runeData)
    for i = 1, #self.bind.talentRuneList do
      self.bind.talentRuneList:getItemCls(i):cellPlayAnim(true, "Show", 0, i * 0.066)
    end
    self.bindComponents.heroTalentAnim:SetTrigger("Show")
    self:refreshCurRankImg()
  elseif isHeroRefresh then
    for _, v in ipairs(self.runeData) do
      v.isInit = true
    end
    self.bind.talentRuneList:clear()
    self.bind.talentRuneList:insert_array(self.runeData)
    for i = 1, #self.bind.talentRuneList do
      self.bind.talentRuneList:getItemCls(i):cellPlayAnim(true, "Show", 0, i * 0.066)
    end
    self:refreshCurRankImg()
  else
    for _, v in ipairs(self.runeData) do
      v.isInit = true
    end
    self.bind.talentRuneList:clear()
    self.bind.talentRuneList:insert_array(self.runeData)
    self:refreshCurRankImg()
  end
  self.lastTalentRuneNums = #rankBreakItems
  self.hero = hero
  self.rankBreakItems = rankBreakItems
  self:refreshBtnsStatus(hero, rankBreakItems)
end

function module:changeRuneList()
  local hero = self:getHero(self.heroGuid)
  local rankTpl = talentRankTpl:getHeroRankTpl(L_HeroStore:getHeroConfigId(hero), L_HeroStore:getHeroRank(hero))
  local rankBreakItems = talentRankTpl:getRankBreakthroughItem(rankTpl)
  local runes = L_HeroStore:getHeroRuneIds(hero)
  self.runeData = {}
  self.allEquiped = true
  local runePosition = runePositions["runePosition_" .. tostring(#rankBreakItems)]
  self:setCanClose(true)
  for k, id in ipairs(rankBreakItems) do
    local tmp = {
      runeId = id,
      isEquiped = not math.isEmpty(runes[k]),
      heroGuid = self.heroGuid,
      slotId = k - 1,
      runePosition = runePosition["rune" .. k],
      curRank = self.currentRank
    }
    table.insert(self.runeData, tmp)
    if #self.bind.talentRuneList == #rankBreakItems then
      self.bind.talentRuneList:change(k, tmp)
    end
    if not tmp.isEquiped then
      self.allEquiped = false
    end
  end
  if #self.bind.talentRuneList ~= #rankBreakItems then
    self.bind.talentRuneList:clear()
    self.bind.talentRuneList:insert_array(self.runeData)
  end
  self.protectTime = 0
  for i = 1, #rankBreakItems do
    self.protectTime = i * 0.1
  end
  Timer.once(1.6 + self.protectTime, function()
    self:setCanClose(false)
  end, self)
  self.hero = hero
  self.rankBreakItems = rankBreakItems
  self:refreshBtnsStatus(hero, rankBreakItems)
end

function module:refreshBtnsStatus(hero, rankBreakItems)
  if hero == nil or rankBreakItems == nil then
    return
  end
  local maxRank = talentRankTpl:getHeroMaxRankNum(L_HeroStore:getHeroConfigId(hero))
  local isMax = maxRank <= L_HeroStore:getHeroRank(hero)
  local isCurrent = self.currentRank == L_HeroStore:getHeroRank(hero)
  self.lastTalentRuneNums = #rankBreakItems
  self.bind.equipBtnActive = not self.allEquiped and isCurrent
  self.bind.breakBtnActive = not isMax and self.allEquiped and isCurrent
  self.bind.maxNodeActive = isMax and table.count(rankBreakItems) == 0 and isCurrent
  self.bind.equipNodeActive = not self.bind.maxNodeActive
  self.bind.backCurrentBtnActive = not isCurrent
  if self.bind.backCurrentBtnActive then
    self.bind.unlockDesAcitve = false
    self.modules.backCurrentBtn:setData({
      txtName = L_WordsTpl:getValue("ui_talent_back_current_rank"),
      callback = function()
        L_UI:open("pageBlank", {timeClose = 0.5})
        self:initPage({isBreak = false, forceRefesh = true})
      end,
      {activeBg = true}
    })
  end
  self:initEquipBtn()
  self:initBreakBtn()
  local tpl_sys = L_GameTpl:getSystemUnlockTpl():getTplById(L_SystemConst.enum.heroTalent)
  self.modules.moduleCurrency:refreshRes(tpl_sys)
end

function module:initEquipBtn()
  if self.runeData == nil then
    return
  end
  local needCost = 0
  for _, rune in ipairs(self.runeData) do
    if not rune.isEquiped then
      local runeTpl = talentRuneTpl:getTplById(rune.runeId)
      local itemId = talentRuneTpl:getRuneItem(runeTpl)
      if 0 < L_BagStore:getItemNum(itemId) then
        local cost = talentRuneTpl:getEquipRuneThroughCoin(runeTpl)
        needCost = needCost + cost
      end
    end
  end
  self.isLackEquipGold = needCost > L_PlayerStore:getCurrencyNum(L_Const.currencyType.gold)
  if self.bind.equipBtnActive then
    self.modules.equipBtn:setData({
      txtName = L_WordsTpl:getValue("ui_hero_rune_quick_equip"),
      callback = handler(self, self.autoEquipRune),
      itemType = L_Const.resType.currency,
      itemId = L_Const.currencyType.gold,
      activeBg = true,
      txt_cost = needCost
    })
  end
end

function module:initBreakBtn()
  local hero = self:getHero(self.heroGuid)
  if L_HeroStore:getHeroRank(hero) ~= self.currentRank then
    return
  end
  local rankTpl = talentRankTpl:getHeroRankTpl(L_HeroStore:getHeroConfigId(hero), L_HeroStore:getHeroRank(hero))
  local needCost = talentRankTpl:getRankBreakthroughCoin(rankTpl)
  self.isLackBreakGold = needCost > L_PlayerStore:getCurrencyNum(L_Const.currencyType.gold)
  if self.bind.breakBtnActive then
    self.modules.breakBtn:setData({
      txtName = L_WordsTpl:getValue("ui_hero_rune_level_up"),
      callback = function()
        L_UI:open("pageTalentBreakConfirm", {
          confirmCallback = function()
            self:onBreakBtnClicked()
          end,
          heroGuid = self.heroGuid,
          txtTitle = L_WordsTpl:getValue("ui_talent_rank_up_ui"),
          hideConfirm = true,
          breakBtnData = {
            itemType = L_Const.resType.currency,
            itemId = L_Const.currencyType.gold,
            txtNum = needCost
          }
        })
      end
    })
  end
  if self.bind.breakBtnActive then
    local rankPlus = talentRankTpl:getHeroRankTpl(L_HeroStore:getHeroConfigId(hero), L_HeroStore:getHeroRank(hero) + 1)
    local rankLevellimit = talentRankTpl:getRankLevelLimit(rankPlus)
    local level = L_HeroStore:getHeroLevel(hero)
    self.bind.unlockDesAcitve = rankLevellimit > level
    self.bind.breakBtnActive = not self.bind.unlockDesAcitve
    if self.bind.unlockDesAcitve then
      self.bind.unlockDes = L_Lang:get(L_WordsTpl:getValue("notice_hero_rankMax"))
    end
  else
    self.bind.unlockDesAcitve = false
  end
  if self.bind.backCurrentBtnActive then
    self.bind.unlockDesAcitve = false
  end
end

function module:setCanClose(canClose)
  self.canClose = not canClose
  self.parent:setMaskActive(canClose)
end

function module:getCanClose()
  return self.canClose
end

function module:getTimelineState()
  return L_Const.heroTimelineState.Skill
end

function module:rankViewChange()
  if not self.heroGuid then
    return
  end
  if not self.currentRank then
    self.currentRank = 1
  end
  local hero = L_HeroStore:getHero(self.heroGuid)
  local maxRank = talentRankTpl:getHeroMaxVisibleRankNum(L_HeroStore:getHeroConfigId(hero))
  self.bind.active_nextRankBtn = maxRank > self.currentRank
  self.bind.active_previousRankBtn = self.currentRank > 1
  self:refreshCurRankImg()
end

function module:refreshCurRankImg()
  if not self.heroGuid then
    return
  end
  if not self.currentRank then
    self.currentRank = 1
  end
  self.bind.curRank = string.format(rankImgPath, self.currentRank >= 10 and tostring(self.currentRank) or "0" .. tostring(self.currentRank))
end

return module
