local this = {}

function this:ctor_local()
  self.onEvent_createDebugTeamHandel = self.onEvent_createDebugTeamHandel or handler(self, self.onEvent_createDebugTeam)
  C_ExternalManager.AddEvent(C_EExternalEventType.CreateDebugTeam, self.onEvent_createDebugTeamHandel)
  self.onEvent_ControlDebugBattlePageHandel = self.onEvent_ControlDebugBattlePageHandel or handler(self, self.onEvent_ControlDebugBattlePage)
  C_ExternalManager.AddEvent(C_EExternalEventType.ControlDebugBattlePage, self.onEvent_ControlDebugBattlePageHandel)
  self.onEvent_RevertDebugPlayerHandel = self.onEvent_RevertDebugPlayerHandel or handler(self, self.onEvent_RevertDebugPlayer)
  C_ExternalManager.AddEvent(C_EExternalEventType.RevertDebugPlayer, self.onEvent_RevertDebugPlayerHandel)
  self.onEvent_DebugBattleExitHandel = self.onEvent_DebugBattleExitHandel or handler(self, self.onEvent_DebugBattleExit)
  C_ExternalManager.AddEvent(C_EExternalEventType.DebugBattleExit, self.onEvent_DebugBattleExitHandel)
end

function this:onEvent_createDebugTeam()
  local playerEntity = L_PlayerManager:getMainControlEntity()
  local pos = playerEntity:getPosition()
  L_CameraManager:bindPoint(pos)
  AzurWorld.playerMgr.myPlayerUnitAdapter.isCustom = false
  AzurWorld.playerMgr.myPlayerUnitAdapter:SwitchToFormationMainControl()
end

function this:onEvent_ControlDebugBattlePage(args)
  if args.boolArg then
    if L_DeviceTpl:getIsPc() then
      L_UI:open("pageWorldBattleLocalPC")
    else
      L_UI:open("pageWorldBattleLocal")
    end
  elseif L_DeviceTpl:getIsPc() then
    L_UI:close("pageWorldBattleLocalPC")
  else
    L_UI:close("pageWorldBattleLocal")
  end
end

function this:onEvent_RevertDebugPlayer()
  AzurWorld.playerMgr.myPlayerUnitAdapter.isCustom = false
  AzurWorld.playerMgr.myPlayerUnitAdapter:SwitchToFormationMainControl()
end

function this:onEvent_DebugBattleExit()
  L_BattleManager:dispose()
  L_UIManager:tmpPauseInput(false)
end

return this
