local this = class("modulePetFavorable", G_UIModuleBase)

function this:bind()
  return {img_pet = "", txt_favorable = ""}
end

function this:methods()
  return {}
end

function this:open(params)
  this.super.open(self)
  self._isOpen = true
  self._infoData = params
  self.uiBinding.gameObject:SetActive(true)
  self:refreshView()
end

function this:refreshView()
  if self._infoData == nil then
    return
  end
  local petId = self._infoData.petId
  local petGuid = self._infoData.petGuid
  local petLvUp = self._infoData.lvUp
  local petFavorUp = self._infoData.favorUp
  local favorableContent
  if petLvUp ~= nil and 0 < petLvUp then
    favorableContent = L_WordsTpl:getValue("ui_modulePetFavorable_02", {
      [0] = petLvUp
    })
  elseif petFavorUp ~= nil and 0 < petFavorUp then
    favorableContent = L_WordsTpl:getValue("ui_modulePetFavorable_01", {
      [0] = petFavorUp
    })
  end
  self.bind.txt_favorable = favorableContent or ""
  local isSpecialPet = false
  if petId == nil then
    local petItem = L_PetStore:getPetItem(petGuid)
    petId = petItem.id
    isSpecialPet = petItem:isSpecialPet()
  end
  local tpl = L_GameTpl:getPetTpl():getTplById(petId)
  local icon = L_GameTpl:getPetTpl():getPetIcon(tpl, isSpecialPet)
  self.bind.img_pet = icon
  self:playStartAnim()
end

function this:setCloseCallBack(callBack)
  self._closeCB = callBack
end

function this:playStartAnim()
  self.bindComponents.animation:Play("anim_scienceexp_in_green")
  Timer.once(2, function()
    self:playEndAnim()
  end)
end

function this:playEndAnim()
  self.bindComponents.animation:Play("anim_scienceexp_out")
  Timer.once(0.267, function()
    if self._closeCB then
      self._closeCB(self._infoData)
    end
    self:close()
  end)
end

function this:close()
  this.super.close(self)
  self._isOpen = false
  self._infoData = nil
  self.uiBinding.gameObject:SetActive(false)
end

return this
