local UIMainWinterStormMatching = BaseClass("UIMainWinterStormMatching", UIBaseContainer)
local base = UIBaseContainer
local bg_path = "Bg"
local go_btn_path = "Bg/goBtn"
local tip_text_path = "Bg/TipText"
local time_text_path = "Bg/TimeText"

function UIMainWinterStormMatching:OnCreate()
  base.OnCreate(self)
  self.lod = 1
  self.bg = self:AddComponent(UIBaseContainer, bg_path)
  self.tip_text = self:AddComponent(UIText, tip_text_path)
  self.tip_text:SetLocalText("winter_battlefield_interface_tips1001")
  self.time_text = self:AddComponent(UIText, time_text_path)
  self.Btn = self:AddComponent(UIButton, go_btn_path)
  self.Btn:SetOnClick(function()
    RaceEntranceUtil.GotoOpenView(EnumActivity.ActWinterStorm.Type)
  end)
end

function UIMainWinterStormMatching:OnDestroy()
  self.tip_text = nil
  self.time_text = nil
  self.Btn = nil
  self.bg = nil
end

function UIMainWinterStormMatching:HideSelf()
  self.bg:SetActive(false)
end

function UIMainWinterStormMatching:Refresh()
  local msTime = DataCenter.ActWinterStormManager:GetMatchStartTime()
  if self.lod <= 3 and msTime ~= nil and 0 < msTime then
    self.bg:SetActive(true)
    self:Update1000MS()
  else
    self.bg:SetActive(false)
  end
end

function UIMainWinterStormMatching:Update1000MS()
  if not self.bg:GetActive() then
    return
  end
  local msTime = DataCenter.ActWinterStormManager:GetMatchStartTime()
  if msTime ~= nil and 0 < msTime then
    local curTime = UITimeManager:GetInstance():GetServerSeconds()
    local remainTime = curTime - msTime
    self.time_text:SetText(UITimeManager:GetInstance():SecondToFmtStringWithoutDay(remainTime))
  else
    self.bg:SetActive(false)
  end
end

function UIMainWinterStormMatching:SetLod(lod)
  if self.lod ~= lod then
    self.lod = lod
    self:Refresh()
  end
end

return UIMainWinterStormMatching
