local WorldTroopTransIcon = BaseClass("WorldTroopTransIcon")
local time_text_path = "PosGo/TimeText"
local OnCreate = function(self, go)
  if go ~= nil then
    self.request = go
    self.gameObject = go.gameObject
    self.transform = go.gameObject.transform
  end
  self:ComponentDefine()
end
local OnDestroy = function(self)
  self:RemoveTimer()
  self:ComponentDestroy()
end
local ComponentDefine = function(self)
  self.time_text = self.transform:Find(time_text_path):GetComponent(typeof(CS.SuperTextMesh))
  self.slider = self.transform:GetComponent(typeof(CS.ChangeSceneCircleSlider))
  self.isDoAnim = false
  
  function self.timer_action()
    self:UpdateTime()
  end
  
  self:AddTimer()
end
local ComponentDestroy = function(self)
  self.time_text = nil
  self.slider = nil
end
local RemoveTimer = function(self)
  if self.timer ~= nil then
    self.timer:Stop()
    self.timer = nil
  end
end
local AddTimer = function(self)
  if self.timer == nil then
    self.timer = TimerManager:GetInstance():GetTimer(1, self.timer_action, self, false, false, false)
  end
  self.timer:Start()
end
local SetShowTime = function(self, startTime, endTime)
  self.startTime = startTime
  self.endTime = endTime
  self.slider:Init(self.startTime, self.endTime)
  self.isDoAnim = true
  self:UpdateTime()
end
local UpdateTime = function(self)
  if self.isDoAnim then
    local curTime = UITimeManager:GetInstance():GetServerTime()
    local timeLeft = self.endTime - curTime
    if 0 < timeLeft then
      self.time_text.text = UITimeManager:GetInstance():MilliSecondToFmtString(timeLeft)
    else
      self.time_text.text = "00:00:00"
      self.isDoAnim = false
    end
  end
end
WorldTroopTransIcon.OnCreate = OnCreate
WorldTroopTransIcon.OnDestroy = OnDestroy
WorldTroopTransIcon.ComponentDefine = ComponentDefine
WorldTroopTransIcon.ComponentDestroy = ComponentDestroy
WorldTroopTransIcon.AddTimer = AddTimer
WorldTroopTransIcon.SetShowTime = SetShowTime
WorldTroopTransIcon.UpdateTime = UpdateTime
WorldTroopTransIcon.RemoveTimer = RemoveTimer
return WorldTroopTransIcon
