local UIGuidePickGarbageNormalBubble = BaseClass("UIGuidePickGarbageNormalBubble")
local ResourceManager = CS.GameEntry.Resource
local icon_path = "Go/Bg/Icon"
local bg_path = "Go/Bg"
local OnCreate = function(self, go)
  if go ~= nil then
    self.request = go
    self.gameObject = go.gameObject
    self.transform = go.gameObject.transform
  end
  self:ComponentDefine()
  self:DataDefine()
end
local OnDestroy = function(self)
  self:ComponentDestroy()
  self:DataDestroy()
end
local ComponentDefine = function(self)
  if not self.defend then
    self.icon_sprite = self.transform:Find(icon_path):GetComponent(typeof(CS.SpriteMeshRenderer))
    self.bg_sprite = self.transform:Find(bg_path):GetComponent(typeof(CS.SpriteMeshRenderer))
    self.bg = self.transform:Find(bg_path):GetComponent(typeof(CS.UIEventTrigger))
    
    function self.bg.onPointerClick()
      self:OnClick()
    end
    
    self.defend = true
  end
end
local ComponentDestroy = function(self)
  self.bg.onPointerClick = nil
  self.icon_sprite = nil
  self.bg_sprite = nil
end
local DataDefine = function(self)
end
local DataDestroy = function(self)
  self.defend = nil
end
local ReInit = function(self, icon, bg, index, rewardType, rewardId)
  self.icon_sprite:LoadSprite(icon)
  self.bg_sprite:LoadSprite(bg)
  self.rewardType = rewardType
  self.rewardId = rewardId
  self:UpdatePosition(index)
end
local UpdatePosition = function(self, index)
  if self.index ~= index then
    local worldPos = SceneUtils.TileIndexToWorld(index)
    self.transform.position = worldPos
    self.index = index
  end
end
local OnClick = function(self)
  local pointData = DataCenter.CityPointDataManager:GetPointDataByPointId(self.index)
  if pointData ~= nil and pointData.type == CityPointType.GarbageReward then
    local soundPath = ""
    if self.rewardType == RewardType.WATER then
      soundPath = SoundAssets.Music_Effect_Water
    elseif self.rewardId == tostring(SpeedUpItemId) then
      soundPath = SoundAssets.Music_Effect_Crystal
    elseif self.rewardType == RewardType.METAL then
      soundPath = SoundAssets.Music_Effect_Crystal
    elseif self.rewardType == RewardType.RESOURCE_ITEM then
      soundPath = SoundAssets.Music_Effect_Product1
    end
    if not string.IsNullOrEmpty(soundPath) then
      CS.GameEntry.Sound:PlayEffect(soundPath)
    end
    UIUtil.OnClickCity(self.index, pointData.type)
  end
end
local GetGuideObject = function(self)
  return self.icon_sprite.gameObject
end
UIGuidePickGarbageNormalBubble.OnCreate = OnCreate
UIGuidePickGarbageNormalBubble.OnDestroy = OnDestroy
UIGuidePickGarbageNormalBubble.ComponentDefine = ComponentDefine
UIGuidePickGarbageNormalBubble.ComponentDestroy = ComponentDestroy
UIGuidePickGarbageNormalBubble.DataDefine = DataDefine
UIGuidePickGarbageNormalBubble.DataDestroy = DataDestroy
UIGuidePickGarbageNormalBubble.ReInit = ReInit
UIGuidePickGarbageNormalBubble.UpdatePosition = UpdatePosition
UIGuidePickGarbageNormalBubble.OnClick = OnClick
UIGuidePickGarbageNormalBubble.GetGuideObject = GetGuideObject
return UIGuidePickGarbageNormalBubble
