local this = class("modulePetFavorability", G_UIModuleBase)
local petFavorabilityTpl = L_GameTpl:getPetFavorabilityTpl()

function this.bind()
  return {
    favorability_lv = "",
    favorability_cur = "",
    favorability_percent = 0
  }
end

function this.methods()
  return {
    onClick_petFavor = function(self)
      if table.isEmpty(self.pet) or math.isEmpty(self.pet.hero_id) then
        return
      end
      L_UI:open("pagePetFavorDetail", {
        petGuid = self.pet.guid
      })
    end
  }
end

function this:setGuid(guid)
  local pet = L_PetStore:getPetItem(guid)
  self.pet = pet
  local curLevel = pet:petFavorLv()
  self.bind.favorability_lv = tostring(pet:petFavorLv())
  local curExp = pet:petFavorVal()
  if math.isEmpty(curLevel) then
    errorf("\230\143\144\231\164\186\231\173\150\229\136\146\231\148\168\239\188\154\229\174\160\231\137\169configId" .. pet.id .. "\230\178\161\230\156\137\233\133\141\231\189\174\229\165\189\230\132\159\229\186\166,\229\165\189\230\132\159\229\186\166\231\173\137\231\186\167\228\184\186\231\169\186")
    self.bind.favorability_cur = "0/0"
    self.bind.favorability_percent = 0
    return
  end
  if petFavorabilityTpl:getIsMaxLv(curLevel) then
    self.bind.favorability_cur = L_WordsTpl:getValue("notice_pagePetFavorDetail")
    self.bind.favorability_percent = 1
  else
    self.bind.favorability_cur = string.format("%d/%d", curExp, petFavorabilityTpl:getUpgradeExp(curLevel))
    self.bind.favorability_percent = curExp / petFavorabilityTpl:getUpgradeExp(curLevel)
  end
end

return this
