function Lobby.resetSelectedObject(H)if UserInputService.GamepadEnabled then GuiService.SelectedObject=H.navigationsRefs[1]:getValue()end end function Lobby.startMatchmaking(G,H)G:setState({status="\099\111\110\110\101\099\116\105\110\103"})local n={type="\074\079\073\078";queue_selection=H}G.joinEvent:FireServer(n)G:resetSelectedObject()end function Lobby.stopMatchmaking(H)H:setState({status="\114\101\097\100\121"})local G={type="\067\065\078\067\069\076"}H.joinEvent:FireServer(G)H:resetSelectedObject()end function Lobby.init(H)local G=Util.playerIsBot(Players.LocalPlayer)H:setState({isBot=G})local n={}for H,G in ipairs(Conf.ui_mode_list)do table.insert(n,Roact.createRef())end H.navigationsRefs=n end function Lobby.didMount(H)H.statusEvent=ReplicatedStorage:WaitForChild("\083\116\097\116\117\115\069\118\101\110\116")H.joinEvent=ReplicatedStorage:WaitForChild("\074\111\105\110\069\118\101\110\116")H.connection=H.statusEvent.OnClientEvent:Connect(function(G)H:setState({status=G.canceled and"\114\101\097\100\121";statusText=G.statusText})end)if H.state.isBot then H:startMatchmaking()end H:resetSelectedObject()end function Lobby.willUnmount(H)H.connection:Disconnect()end function Lobby.render(H)local G={}local n=H.state.status or"\114\101\097\100\121"if H.state.isBot then G.botLabel=Roact.createElement("\084\101\120\116\076\097\098\101\108",{Text="\084\104\105\115 \112\108\097\121\101\114 \104\097\115 \098\101\101\110 \102\108\097\103\103\101\100 \097\115 \097 \116\101\115\116 \098\111\116",Position=UDim2.new(.5,0,.5,0),Size=UDim2.new(0,500,0,26)})else if n=="\114\101\097\100\121"then G.Layout=Roact.createElement("\085\073\076\105\115\116\076\097\121\111\117\116",{SortOrder=Enum.SortOrder.LayoutOrder,FillDirection=Enum.FillDirection.Vertical;Padding=UDim.new(0,20)})for n,Q in ipairs(Conf.ui_mode_list)do local O=Conf.modes[Q]G["\112\108\097\121\066\117\116\116\111\110\046"..Q]=Roact.createElement("\084\101\120\116\066\117\116\116\111\110",{[Roact.Ref]=H.navigationsRefs[n],NextSelectionUp=H.navigationsRefs[n-1];NextSelectionDown=H.navigationsRefs[n+1];Size=UDim2.new(0,300,0,50),Font=Enum.Font.GothamBlack,TextSize=32,BorderSizePixel=3,Text=O.title;BackgroundColor3=Color3.fromRGB(255,239,39);[Roact.Event.Activated]=function()H:startMatchmaking(Q)end;LayoutOrder=n})end else G.cancelButton=Roact.createElement("\084\101\120\116\066\117\116\116\111\110",{[Roact.Ref]=H.navigationsRefs[1];Size=UDim2.new(0,300,0,50),Font=Enum.Font.GothamBlack;TextSize=32;BorderSizePixel=3,Text="\067\065\078\067\069\076",BackgroundColor3=Color3.fromRGB(255,200,39),[Roact.Event.Activated]=function()H:stopMatchmaking()end})end end if H.state.statusText then G.joinStatus=Roact.createElement("\084\101\120\116\076\097\098\101\108",{Text=H.state.statusText})end return Roact.createElement("\083\099\114\101\101\110\071\117\105",{IgnoreGuiInset=true;ResetOnSpawn=false,ZIndexBehavior=Enum.ZIndexBehavior.Sibling},{Roact.createElement("\070\114\097\109\101",{Transparency=1;AnchorPoint=Vector2.new(1,1);Size=UDim2.new(0,400,0,280);Position=UDim2.new(1,0,1,0)},G)})end
------------------------------------------------

function Lobby:resetSelectedObject()
	if UserInputService.GamepadEnabled then
		GuiService.SelectedObject = self.navigationsRefs[1]:getValue()
	end
end

function Lobby:startMatchmaking(modeSelection)
	self:setState({
		status = "connecting",
	})

	-- TEMP:  Forcing queue selection
	local joinData = {
		type = "JOIN",
		queue_selection = modeSelection,
	}

	self.joinEvent:FireServer(joinData)

	self:resetSelectedObject()
end

function Lobby:stopMatchmaking()
	self:setState({
		status = "ready",
	})

	local data = {
		type = "CANCEL",
	}

	self.joinEvent:FireServer(data)

	self:resetSelectedObject()
end

function Lobby:init()
	local isBot = Util.playerIsBot(Players.LocalPlayer)

	self:setState({
		isBot = isBot,
	})

	local refs = {}

	for _, _ in ipairs(Conf.ui_mode_list) do
		table.insert(refs, Roact.createRef())
	end

	self.navigationsRefs = refs
end

function Lobby:didMount()
	self.statusEvent = ReplicatedStorage:WaitForChild("StatusEvent")
	self.joinEvent = ReplicatedStorage:WaitForChild("JoinEvent")

	self.connection = self.statusEvent.OnClientEvent:Connect(function(data)
		self:setState({
			status = data.canceled and "ready",
			statusText = data.statusText,
		})
	end)

	if self.state.isBot then
		self:startMatchmaking()
	end

	self:resetSelectedObject()
end

function Lobby:willUnmount()
	self.connection:Disconnect()
end

function Lobby:render()
	local children = {}

	local status = self.state.status or "ready"

	if self.state.isBot then
		children.botLabel = Roact.createElement("TextLabel", {
			Text = "This player has been flagged as a test bot",
			Position = UDim2.new(0.5, 0, 0.5, 0),
			Size = UDim2.new(0, 500, 0, 26),
		})
	else
		if status == "ready" then
			children.Layout = Roact.createElement("UIListLayout", {
				SortOrder = Enum.SortOrder.LayoutOrder,
				FillDirection = Enum.FillDirection.Vertical,
				Padding = UDim.new(0, 20),
			})

			for i, mode in ipairs(Conf.ui_mode_list) do
				local data = Conf.modes[mode]

				children["playButton." .. mode] = Roact.createElement("TextButton", {
					[Roact.Ref] = self.navigationsRefs[i],
					NextSelectionUp = self.navigationsRefs[i - 1],
					NextSelectionDown = self.navigationsRefs[i + 1],
					Size = UDim2.new(0, 300, 0, 50),
					Font = Enum.Font.GothamBlack,
					TextSize = 32,
					BorderSizePixel = 3,
					Text = data.title,
					BackgroundColor3 = Color3.fromRGB(255, 239, 39),
					[Roact.Event.Activated] = function()
						self:startMatchmaking(mode)
					end,
					LayoutOrder = i,
				})
			end
		else
			children.cancelButton = Roact.createElement("TextButton", {
				[Roact.Ref] = self.navigationsRefs[1],
				Size = UDim2.new(0, 300, 0, 50),
				Font = Enum.Font.GothamBlack,
				TextSize = 32,
				BorderSizePixel = 3,
				Text = "CANCEL",
				BackgroundColor3 = Color3.fromRGB(255, 200, 39),
				[Roact.Event.Activated] = function()
					self:stopMatchmaking()
				end,
			})
		end
	end

	if self.state.statusText then
		children.joinStatus = Roact.createElement("TextLabel", {
			Text = self.state.statusText,
		})
	end

	return Roact.createElement("ScreenGui", {
		IgnoreGuiInset = true,
		ResetOnSpawn = false,
		ZIndexBehavior = Enum.ZIndexBehavior.Sibling,
	}, {
		Roact.createElement("Frame", {
			Transparency = 1,
			AnchorPoint = Vector2.new(1, 1),
			Size = UDim2.new(0, 400, 0, 280),
			Position = UDim2.new(1, 0, 1, 0),
		}, children),
	})
end
