local this = class("cellCaptureCardInfo", G_UIModuleBase)

function this.bind()
  return {txt_cardCount = "", txt_shortCutKet = ""}
end

function this.methods()
  return {
    onClick_sphere = function(self)
      self:onClick()
    end
  }
end

function this:open()
  if self.bind.quality == 0 then
    self.keyType = C_InputManager_KeyType.EMainPetCatchBall1
  elseif self.bind.quality == 1 then
    self.keyType = C_InputManager_KeyType.EMainPetCatchBall2
  elseif self.bind.quality == 2 then
    self.keyType = C_InputManager_KeyType.EMainPetCatchBall3
  elseif self.bind.quality == 3 then
    self.keyType = C_InputManager_KeyType.EMainPetCatchBall4
  elseif self.bind.quality == 4 then
    self.keyType = C_InputManager_KeyType.EMainPetCatchBall5
  end
  L_ShortCutManager:registerShortCut(self.parent.pageName, self.keyType, function(value)
    self:onClick()
  end)
  self.bind.txt_shortCutKet = tostring(self.bind.quality + 1)
  if self.bind.cnt > 9999 then
    self.bind.txt_cardCount = 9999
  else
    self.bind.txt_cardCount = tostring(self.bind.cnt)
  end
end

function this:close()
  L_ShortCutManager:removeShortCut(self.parent.pageName)
end

function this:onClick()
  if self.parent.bBlockHand or self.parent.catchIsStart or self.parent.isClose or self.parent.isPlayingAnim then
    return
  end
  if self.bind.cnt <= 0 then
    L_FlyMsgManager:showNormalMsg(L_WordsTpl:getValue("notice_noItem"))
    return
  end
  self:emit("onClick_sphere", self.bind.sphereId, self.bind.cnt, self.bind.quality)
end

function this:refreshCnt(cnt)
  if 9999 < cnt then
    cnt = 9999
  end
  self.bind.txt_cardCount = tostring(cnt)
end

function this:playInitAnim(selectId)
  local animName = self.bind.sphereId == selectId and "anim_battlecapture_card_show_select" or "show_none"
  self.bindComponents.anim:Play(animName, 0)
end

function this:playSelectAnim(oldId, newId)
  if oldId == self.bind.sphereId then
    self.bindComponents.anim:Play("anim_battlecapture_card_to_none", 0)
  end
  if newId == self.bind.sphereId then
    self.bindComponents.anim:Play("toSelect", 0)
  end
end

function this:playUnSelectAnim(id)
  if id ~= self.bind.sphereId then
    return
  end
  self.bindComponents.anim:Play("anim_battlecapture_card_to_none", 0)
end

return this
