-- local Warning = require(script.Warning)


local App = Roact.PureComponent:extend("App")

function App:init()
	self.state = {
		absoluteSize = Vector2.new(0, 0),
		gameStage = StageManager.getStage()
	}

	self.onAbsoluteSizeChange = function(rbx)
		self:setState({
			absoluteSize = rbx.AbsoluteSize
		})
	end
end

function App:didMount()
	self.broadcastConnection = Broadcast.registerHandler("GAME_STAGE_CHANGE", function(stage)
		self:setState({
			gameStage = stage,
		})
	end)
end

function App:willUnmount()
	Broadcast.unregisterHandler(self.broadcastConnection)
end

function App:render()
	local stage = self.state.gameStage

	if stage == "Lobby" then
		return Roact.createFragment({
			Lobby = Roact.createElement(Lobby)
		})
	else
		local hud = {
			HudHealthBar = Roact.createElement(HudHealthBar),
			Version = Roact.createElement(Version),
			Building = Roact.createElement(Building),
			ToggleBuildingButton = Roact.createElement(ToggleBuildingButton),
			RotateButton = Roact.createElement(RotateButton),
			PingList = Roact.createElement(PingList),
			EventStream = Roact.createElement(EventStream),
			-- Warning = Roact.createElement(Warning),
		}

		if stage == "Queue" and not Conf.disable_queue then
			-- TODO:  Queue specific UI
			hud.QueueStatus = Roact.createElement(Queue, {
				screenSize = self.state.absoluteSize,
			})
		else
			if Conf.debug_mode then
				hud.ReplicationFocus = Roact.createElement(ReplicationFocus)
				hud.PlayerCount = Roact.createElement(PlayerCount)
			end
			hud.Leaderboard = Roact.createElement(Leaderboard)
			hud.LeaderboardButton = Roact.createElement(LeaderboardButton)
			hud.ToggleMapButton = Roact.createElement(ToggleMapButton)
			hud.TeamScoreDisplay = Roact.createElement(TeamScoreDisplay)
			hud.EndGameMessage = Roact.createElement(EndGameMessage)
		end

		return Roact.createFragment({
			GameUI = Roact.createElement("ScreenGui", {
				IgnoreGuiInset = true,
				ResetOnSpawn = false,
				ZIndexBehavior = Enum.ZIndexBehavior.Sibling,
				[Roact.Change.AbsoluteSize] = self.onAbsoluteSizeChange,
			}, hud),
			-- These are billboard guis
			PickupInfo = Roact.createElement(PickupInfo),
			ActionButton = Roact.createElement(ActionButton),
			TeamIndicators = Roact.createElement(TeamIndicators),
		})
	end
end

return App
