local this = class("cellTopStatistics", G_UIModuleBase)
local petTpl = L_GameTpl:getPetTpl()
local elementTpl = L_GameTpl:getElementTypeTpl()
local trialPetTpl = L_GameTpl:getTrialPetTpl()
local playerColor = "UI/Atlas/PetDuel/tex_petduel_bar_tab02.png"
local enemyColor = "UI/Atlas/PetDuel/tex_petduel_bar_tab03.png"

function this.bind()
  return {
    petIcon = "",
    petName = "",
    valueText = "",
    valueSlider = 0,
    img_sliderColor = ""
  }
end

function this.methods()
  return {}
end

function this:refresh()
  if not self.isBind then
    return
  end
  if self.bind.isPlayer then
    self:setPlayerData()
  else
    self:setEnemyData()
  end
  local value = L_HeroManager:addComma(math.floor(self.bind.value))
  self.bind.valueText = value
  if self.bind.value == 0 then
    self.bind.valueSlider = 0
  else
    self.bind.valueSlider = self.bind.value / self.bind.maxValue
  end
end

function this:setEnemyData()
  local tpl = petTpl:getTplById(self.bind.id)
  self.bind.petIcon = petTpl:getPetIcon(tpl)
  self.bind.petName = petTpl:getName(tpl, false)
  self.bind.img_sliderColor = enemyColor
end

function this:setPlayerData()
  if self.bind.is_trial then
    self:refreshSystemPetInfo(self.bind)
  else
    self:refreshPlayerPetInfo(self.bind)
  end
  self.bind.img_sliderColor = playerColor
end

function this:refreshSystemPetInfo(petInfo)
  local trialId = petInfo.id
  local trialTpl = trialPetTpl:getTplById(trialId)
  local petId = trialPetTpl:getTrialPet(trialTpl)
  local tpl = petTpl:getTplById(petId)
  self.bind.petIcon = petTpl:getPetIcon(tpl)
  self.bind.petName = L_KiBoDuelManager:getPetNameBySlot(petInfo.slotId)
end

function this:refreshPlayerPetInfo(petInfo)
  local id = petInfo.id
  local petData = L_PetStore:getPetItem(id)
  if petData then
    local tpl = petTpl:getTplById(petData.id)
    self.bind.petIcon = petTpl:getPetIcon(tpl, petData:isSpecialPet())
    self.bind.petName = petTpl:getName(tpl, petData:isSpecialPet())
  end
end

return this
