local module = class("cellUseFoodHero", G_UIModuleBase)

function module:ctor(...)
  module.super.ctor(self, ...)
  self.data = {photoEntity = nil}
end

local HP_COLOR = {
  red = CS.UnityEngine.Color(0.8392156862745098, 0.20784313725490197, 0.20784313725490197),
  orange = CS.UnityEngine.Color(0.9686274509803922, 0.6980392156862745, 0.2235294117647059),
  green = C_LuaUtility.ParseHtmlStringColor("#86F68E")
}

function module.bind()
  return {
    img_icon = "",
    hero = true,
    charge = false,
    hpText = "",
    heroStatus = false,
    hp = 0,
    addHp = 0,
    scrollList_buff = {
      moduleName = "pages/Bag/BagUse/cellUseFoodHeroBuff"
    }
  }
end

function module.methods()
  return {
    onClick_selectHero = function(self)
      if not math.isEmpty(self.bind.heroId) then
        self:emit("onClick_selectHero", self.bind.heroId)
      end
    end
  }
end

function module:refresh()
  if math.isEmpty(self.bind.heroId) then
    local chargeData = L_StarHealingStore:getCharge()
    local limitCharge = "/" .. L_StarHealingStore:getMaxCharge()
    self.bind.hpText = tostring(chargeData.cur_value) .. limitCharge
    self.bind.hp = self.bind.scale_hp
    self.bind.addHp = self.bind.scale_add
    self.bind.hero = false
    self.bind.charge = true
    return
  end
  self.bind.hero = true
  self.bind.charge = false
  if not string.isEmpty(self.bind.url_defaultHero) then
    if self.data.photoEntity == nil then
      self.data.photoEntity = L_PhotoManager:bindPhotoEntity(self.bindComponents.img_icon.gameObject, self.bind.url_defaultHero)
    else
      self.data.photoEntity:bindGameObject(self.bindComponents.img_icon.gameObject)
    end
  end
  local color = HP_COLOR.green
  self.bind.heroStatus = false
  if self.bind.scale_hp < 0.3 and self.bind.scale_hp > 0 then
    color = HP_COLOR.red
  elseif self.bind.scale_hp < 0.6 and self.bind.scale_hp >= 0.3 then
    color = HP_COLOR.orange
  elseif self.bind.scale_hp <= 0 then
    color = HP_COLOR.red
    self.bind.heroStatus = true
  end
  self.bind.hp = self.bind.scale_hp
  self.bind.addHp = self.bind.scale_add
  self.bindComponents.img_hp.color = color
end

function module:resetAddhpWhileUnselect()
  self.bind.addHp = 0
end

return module
