local this = class("moduleBattleAttackBtn", G_UIModuleBase)
local constAttackBtnStatus = {init = 1, boostDo = 2}

function this.bind()
  return {}
end

function this.methods()
  return {
    onClick_attack = function(self)
      L_PlayerManager:fireAttackUp()
    end
  }
end

function this:open(...)
  this.super.open(self, ...)
  self.data = {
    attackBtnState = constAttackBtnStatus.init
  }
  L_BattleDataManager:addListener(L_BattleDataManager.event.refreshAttackStatus, self.onEvent_refreshAttackStatus, self)
  L_BattleDataManager:addListener(L_BattleDataManager.event.onCastSkill, self.onEvent_onCastSkill, self)
  L_PlayerManager:addListener(L_PlayerManager.event.outMountEnd, self.onPlayerOutMount, self)
end

function this:onPlayerOutMount()
  self.bind.goContent = true
  self:resetEffect()
end

function this:show()
  self:resetEffect()
end

function this:resetEffect()
  self.data.attackBtnState = constAttackBtnStatus.init
end

function this:close(...)
  this.super.close(self, ...)
  L_BattleDataManager:removeListener(L_BattleDataManager.event.refreshAttackStatus, self.onEvent_refreshAttackStatus, self)
  L_BattleDataManager:removeListener(L_BattleDataManager.event.onCastSkill, self.onEvent_onCastSkill, self)
  L_PlayerManager:removeListener(L_PlayerManager.event.outMountEnd, self.onPlayerOutMount, self)
end

function this:onEvent_onCastSkill(args)
  local skillId = args.intArg
  local mainHero = L_PlayerManager:getMainHeroEntity()
  if mainHero == nil then
    return
  end
  local skill = mainHero:getCsEntity().data.skillProperty:GetSkillBySlot(L_Const.C_ESkillSlotType.EvadeBoostAttack)
  if skill and skill.id == skillId then
    self.bindComponents.attackAnim:Play("anim_battle_attack_fightback_cost", 1)
    self.data.attackBtnState = constAttackBtnStatus.boostDo
  end
end

function this:onEvent_refreshAttackStatus(args)
  if args.intArg == L_Const.C_ESkillSlotType.EvadeBoostAttack then
    self.bindComponents.attackAnim:Play("anim_battle_attack_fightback_ready", 1)
  elseif self.data.attackBtnState == constAttackBtnStatus.init then
    self.bindComponents.attackAnim:Play("anim_battle_attack_fightback_fade", 1)
  else
    self.data.attackBtnState = constAttackBtnStatus.init
  end
end

return this
