local this = class("pagePlatformLogin", G_UIPageBase)
local accountServer = {
  ip = C_InfoManager.ServerIp,
  port = tonumber(C_InfoManager.ServerPort)
}

function this.bind()
  return {
    loginModuleBox = {
      type = "toggleModule",
      moduleLogin = {
        assetName = "UI/Pages/Platform/moduleLogin",
        moduleName = "pages/platform/moduleLogin"
      }
    },
    loginModuleName = "",
    bgActive = false
  }
end

function this.methods()
  return {}
end

function this:ctor()
  this.super.ctor(self)
end

function this:preOpen(options)
  this.super.preOpen(self, options)
  C_GameAudioManager.StopBgm()
  C_LoginMovieHelper.PlayLoginMovie()
  self:registerEvents()
  self:InitLoginData()
  self:tryCreateLoginModule()
end

function this:tryShowAnnouncementOfGateway()
  local announcementResponeDataInfo = L_AnnouncementStore:getAnnouncementResponeDataInfoOfGateway()
  local announcementMetaData = announcementResponeDataInfo and announcementResponeDataInfo:getAnnouncementMetaData()
  if not announcementResponeDataInfo or not announcementMetaData then
    errorf("\229\134\133\231\189\145-gm\230\156\141\231\187\180\230\138\164\231\138\182\230\128\129\239\188\140\228\189\134\230\156\170\230\142\168\233\128\129\231\189\145\229\133\179\229\133\172\229\145\138")
    self:creatModule()
    return
  end
  local title = announcementMetaData:getTitle()
  local url = announcementMetaData:getContent()
  L_UI:open("pageGatewayAnnouncementWindow", {
    title = title,
    url = url,
    txtOK = L_WordsTpl:getTplById("common_window_1"),
    onClickOkCallback = function()
      self:creatModule()
    end,
    onClickCloseCallback = function()
      self:creatModule()
    end
  })
end

function this:open()
end

function this:show()
  self.closeScene = false
end

function this:hide(options)
  if self.closeScene then
    return
  end
  self:dealClose()
end

function this:escHandle()
end

function this:close(options)
  if self.closeScene then
    return
  end
  self:dealClose()
end

function this:registerEvents()
  L_LoginManager:addListener(L_LoginManager.events.hasSyncIsSeverOpen, self.tryCreateLoginModule, self)
  L_AnnouncementStore:listenCallFunc(L_AnnouncementStore.event.syncAnnouncementResponeDataInfoOfGatewayComplete, self.tryShowAnnouncementOfGateway, self)
end

function this:initBackground()
end

function this:InitLoginData()
end

function this:tryCreateLoginModule()
  if L_LoginManager:getIsSeverOpen() == true then
    self:creatModule()
  else
    L_LoginManager:getAnnouncementOnLogin(function(data, code)
      L_AnnouncementStore:syncAnnouncementResponeDataInfoOfGateway(data, code)
    end)
  end
end

function this:creatModule()
  self.bind.loginModuleName = "moduleLogin"
end

function this:dealClose()
  local backgrondScene = C_GameObject.Find("LoginBackgroundScene")
  if backgrondScene then
    backgrondScene.gameObject:SetActive(false)
    C_GameObject.Destroy(backgrondScene)
    self.closeScene = true
  end
  self:unRegisterEvents()
  C_LoginMovieHelper.StopLoginMovie()
end

function this:unRegisterEvents()
  L_LoginManager:removeListener(L_LoginManager.events.hasSyncIsSeverOpen, self.tryCreateLoginModule)
  L_AnnouncementStore:unListenCallFunc(L_AnnouncementStore.event.syncAnnouncementResponeDataInfoOfGatewayComplete, self.tryShowAnnouncementOfGateway)
end

return this
