local this = class("moduleDuelSkillRelease", G_UIModuleBase)
local skillTpl = L_GameTpl:getSkillTpl()
local skillLevelTpl = L_GameTpl:getSkillLevelTpl()

function this.bind()
  return {
    skillName = "",
    skillDes = "",
    skillIcon = "",
    contentActive = true
  }
end

function this.methods()
  return {
    onClick_cancleBtn = function(self)
      L_KiBoDuelManager:handleCancelSkillRelease(nil, L_KiBoDuelManager.skillStausEnum.normal)
    end,
    onClick_confirmBtn = function(self)
      L_KiBoDuelManager:handleConfirmSkillRelease(nil, L_KiBoDuelManager.skillStausEnum.normal)
    end
  }
end

function this:open()
  L_KiBoDuelManager:addListener(L_KiBoDuelManager.event.changeSkillStatus, self.onChangeSkillStatus, self)
  L_KiBoDuelManager:addListener(L_KiBoDuelManager.event.restartKiBoDuel, self.restartKiBoDuel, self)
end

function this:close()
  L_KiBoDuelManager:removeListener(L_KiBoDuelManager.event.changeSkillStatus, self.onChangeSkillStatus, self)
  L_KiBoDuelManager:removeListener(L_KiBoDuelManager.event.restartKiBoDuel, self.restartKiBoDuel, self)
end

function this:restartKiBoDuel()
  L_KiBoDuelManager:changeSkillStatus(nil, L_KiBoDuelManager.skillStausEnum.normal)
end

function this:onChangeSkillStatus(data)
  if L_KiBoDuelManager:isInReleaseSkill() then
    self:setSkillSlot(data.slot)
  end
  self.bind.contentActive = L_KiBoDuelManager:isInReleaseSkill()
end

function this:setSkillSlot(slotType)
  local controlEntity = L_PlayerManager:getMainControlEntity()
  if not controlEntity then
    return
  end
  local skillProperty = controlEntity:getCsEntity().data.skillProperty
  local skill = skillProperty:GetSkillBySlot(slotType)
  local skillId = skill.id
  local tpl = skillTpl:getTplById(skillId)
  local icon = skillTpl:getBattleSkillIcon(tpl)
  self.bind.skillIcon = icon
  self.bind.skillName = skillTpl:getName(tpl)
  local levelTpl = skillLevelTpl:getTplByIdAndLevel(skillId, skill.skillLevel)
  local des = skillLevelTpl:getSkillDescribe(levelTpl)
  self.bind.skillDes = des
end

return this
