-- Decompiled with the Synapse X Luau decompiler.


client = nil;
service = nil;
return function(p1)
	local l__FromPlayer__1 = p1.FromPlayer;
	local l__SessionName__2 = p1.SessionName;
	local u1 = nil;
	local l__SessionKey__2 = p1.SessionKey;
	local u3 = {};
	local u4 = nil;
	local l__CanManageUsers__5 = p1.CanManageUsers;
	local u6 = nil;
	local u7 = nil;
	local u8 = {};
	local function u9(p2)
		local l__PlayerName__3 = p2.PlayerName;
		local v4 = false;
		if l__PlayerName__3 ~= "*SYSTEM*" then
			v4 = p2.PlayerDisplayName;
		end;
		local l__Message__5 = p2.Message;
		local v6 = nil;
		if l__PlayerName__3 == "* SYSTEM *" then
			v6 = u7:Add("Frame", {
				Size = UDim2.new(1, 0, 0, 25), 
				BackgroundTransparency = 1, 
				AutomaticSize = "Y", 
				Children = { {
						ClassName = "Frame", 
						Name = "CHATFRAME", 
						Size = UDim2.new(1, -10, 1, -10), 
						Position = UDim2.new(0, 5, 0, 5), 
						BackgroundTransparency = 0.5, 
						AutomaticSize = "Y", 
						Children = { {
								ClassName = "TextLabel", 
								Name = "PlayerName", 
								Size = UDim2.new(0, 0, 0, 14), 
								Position = UDim2.new(0, 1, 0, 1), 
								Text = "   " .. l__PlayerName__3, 
								TextSize = "14", 
								TextXAlignment = "Left", 
								BackgroundTransparency = 1
							}, {
								ClassName = "TextLabel", 
								Name = "Message", 
								Size = UDim2.new(1, 0, 0, 10), 
								Position = UDim2.new(0, 0, 0, 14), 
								Text = "   " .. (l__Message__5 and "<font color='rgb(230,0,0)'>An error has occured</font>"), 
								TextXAlignment = "Left", 
								TextYAlignment = "Top", 
								AutomaticSize = "Y", 
								TextWrapped = true, 
								TextScaled = false, 
								RichText = true, 
								BackgroundTransparency = 1
							} }
					} }
			});
		else
			u7:Add("Frame", {
				Size = UDim2.new(1, 0, 0, 50), 
				BackgroundTransparency = 1, 
				AutomaticSize = "Y", 
				Children = { {
						ClassName = "Frame", 
						Name = "CHATFRAME", 
						Size = UDim2.new(1, -10, 1, -10), 
						Position = UDim2.new(0, 5, 0, 5), 
						BackgroundTransparency = 0.5, 
						AutomaticSize = "Y", 
						Children = { {
								ClassName = "ImageButton", 
								Name = "Icon", 
								Size = UDim2.new(0, 48, 0, 48), 
								Position = UDim2.new(0, 1, 0, 1), 
								Image = p2.Icon and 0
							}, {
								ClassName = "TextLabel", 
								Name = "PlayerName", 
								Size = UDim2.new(1, -55, 0, 15), 
								Position = UDim2.new(0, 55, 0, 0), 
								Text = not v4 and l__PlayerName__3 or string.format("@%s (%s)", l__PlayerName__3, v4), 
								TextSize = "14", 
								TextXAlignment = "Left", 
								BackgroundTransparency = 1
							}, {
								ClassName = "TextLabel", 
								Name = "Message", 
								Size = UDim2.new(1, -55, 0, 10), 
								Position = UDim2.new(0, 55, 0, 15), 
								Text = l__Message__5, 
								TextXAlignment = "Left", 
								TextYAlignment = "Top", 
								AutomaticSize = "Y", 
								TextWrapped = true, 
								TextScaled = false, 
								RichText = true, 
								BackgroundTransparency = 1
							} }
					} }
			});
		end;
		table.insert(u8, v6);
		if #u8 > 200 then
			u8[1]:Destroy();
			table.remove(u8, 1);
		end;
	end;
	if client.UI.Get("PrivateChat" .. l__SessionName__2) then
		return;
	end;
	local v7 = {
		Name = "PrivateChat" .. l__SessionName__2, 
		Title = "Private Chat", 
		Icon = client.MatIcons.Forum, 
		Size = { 500, 300 }
	};
	local u10 = nil;
	function v7.OnClose()
		if u10 then
			u10:Disconnect();
		end;
		client.Remote.Send("Session", l__SessionKey__2, "LeaveSession");
	end;
	local v8 = client.UI.Make("Window", v7);
	u7 = v8:Add("ScrollingFrame", {
		Size = UDim2.new(1, -105, 1, -45), 
		CanvasSize = UDim2.new(0, 0, 0, 0), 
		BackgroundTransparency = 0.9
	});
	u1 = v8:Add("TextBox", {
		Text = "", 
		PlaceholderText = "", 
		Size = UDim2.new(1, -70, 0, 30), 
		Position = UDim2.new(0, 5, 1, -35), 
		ClearTextOnFocus = false, 
		TextScaled = true
	});
	u4 = v8:Add("ScrollingFrame", {
		Size = UDim2.new(0, 100, 1, -75), 
		Position = UDim2.new(1, -100, 0, 0), 
		BackgroundTransparency = 0.5, 
		AutomaticCanvasSize = "Y"
	});
	local v9 = {
		Text = "+", 
		Size = UDim2.new(0, 30, 0, 30), 
		Position = UDim2.new(1, -100, 1, -70)
	};
	local function u11()
		local v10 = {};
		local l__next__11 = next;
		local v12, v13 = service.Players:GetPlayers();
		while true do
			local v14, v15 = l__next__11(v12, v13);
			if not v14 then
				break;
			end;
			local v16 = true;
			for v17, v18 in next, u3 do
				if v18.UserId == v15.UserId then
					v16 = false;
					break;
				end;
			end;
			if v16 then
				table.insert(v10, {
					Text = string.format("@%s (%s)", v15.Name, v15.DisplayName), 
					Data = service.UnWrap(v15)
				});
			end;		
		end;
		local v19 = client.UI.Make("SelectionPrompt", {
			Name = "Add User", 
			Options = v10
		});
		if v19 then
			client.Remote.Send("Session", l__SessionKey__2, "AddPlayerToSession", v19);
		end;
	end;
	local function u12(p3)
		u9({
			PlayerName = "* SYSTEM *", 
			Message = p3, 
			Icon = 0
		});
	end;
	function v9.OnClick()
		if l__CanManageUsers__5 then
			u11();
			return;
		end;
		u12("<i>You are not allowed to manage users</i>");
	end;
	local v20 = v8:Add("TextButton", v9);
	local v21 = v8:Add("TextButton", {
		Text = "-", 
		Size = UDim2.new(0, 30, 0, 30), 
		Position = UDim2.new(1, -35, 1, -70), 
		OnClick = function()
			if l__CanManageUsers__5 then
				if not u6 then
					return;
				end;
			else
				u12("<i>You are not allowed to manage users</i>");
				return;
			end;
			client.Remote.Send("Session", l__SessionKey__2, "RemovePlayerFromSession", u6);
			u6 = nil;
		end
	});
	local v22 = {
		Text = "Send", 
		Size = UDim2.new(0, 60, 0, 30), 
		Position = UDim2.new(1, -65, 1, -35)
	};
	local function u13()
		local v23 = service.Trim(u1.Text);
		if v23 ~= "" then
			client.Remote.Send("Session", l__SessionKey__2, "SendMessage", v23);
		end;
	end;
	function v22.OnClick()
		u13();
		u1.Text = "";
	end;
	local v24 = v8:Add("TextButton", v22);
	local v25 = service.New("UIListLayout", {
		Parent = u7, 
		FillDirection = "Vertical", 
		HorizontalAlignment = "Left", 
		VerticalAlignment = "Bottom", 
		SortOrder = "LayoutOrder"
	});
	v24.BackgroundColor3 = v24.BackgroundColor3:lerp(Color3.new(0, 0, 0), 0.1);
	u1.FocusLost:Connect(function(p4)
		if p4 then
			u13();
			u1.Text = "";
			u1:CaptureFocus();
		end;
	end);
	v25:GetPropertyChangedSignal("AbsoluteContentSize"):Connect(function()
		u7.CanvasSize = UDim2.new(0, 0, 0, v25.AbsoluteContentSize.Y);
		u7.CanvasPosition = Vector2.new(0, v25.AbsoluteContentSize.Y);
	end);
	if p1.History then
		for v26, v27 in ipairs(p1.History) do
			local l__Sender__28 = v27.Sender;
			u9({
				PlayerName = l__Sender__28.Name, 
				PlayerDisplayName = l__Sender__28.DisplayName, 
				Message = v27.Message, 
				Icon = l__Sender__28.Icon and 0
			});
		end;
	end;
	local function u14(p5)
		u4:ClearAllChildren();
		u3 = p5;
		for v29, v30 in next, p5 do
			local v31 = u4:Add("TextButton", {
				Text = string.format("@%s (%s)", v30.Name, v30.DisplayName), 
				Size = UDim2.new(1, 0, 0, 25), 
				TextScaled = true, 
				TextWarped = true, 
				BackgroundTransparency = 1
			});
			if l__CanManageUsers__5 then
				local v32 = v31.BackgroundColor3:Lerp(Color3.fromRGB(9, 67, 255), 0.1);
				if v30.UserId and v30.UserId ~= service.Players.LocalPlayer.UserId then
					v31.MouseButton1Down:Connect(function()
						for v33, v34 in ipairs(u4:GetChildren()) do
							if v34:IsA("TextButton") or v34:IsA("Frame") then
								v34.BackgroundTransparency = 1;
							end;
						end;
						u6 = v30;
						v31.BackgroundTransparency = 0;
						v31.BackgroundColor3 = v32;
					end);
				end;
			end;
		end;
		u4.CanvasSize = UDim2.new(0, 0, 0, service.New("UIListLayout", {
			Parent = u4, 
			FillDirection = "Vertical", 
			HorizontalAlignment = "Center", 
			VerticalAlignment = "Top", 
			SortOrder = "LayoutOrder"
		}).AbsoluteContentSize.Y);
	end;
	u10 = service.Events.SessionData:Connect(function(p6, p7, ...)
		local v35 = { ... };
		if l__SessionKey__2 == p6 then
			if p7 == "PlayerSentMessage" then
				local v36 = v35[1];
				if u9 then
					u9({
						PlayerName = v36.Name, 
						PlayerDisplayName = v36.DisplayName, 
						Message = v35[2], 
						Icon = v36.Icon and 0
					});
					return;
				end;
			else
				if p7 == "UpdatePeerList" then
					u14(v35[1]);
					return;
				end;
				if p7 == "RemovedFromSession" then
					u12("<i>You have been removed from this chat session</i>");
					return;
				end;
				if p7 == "AddedToSession" then
					u12("<i>You have been added to this chat session</i>");
				end;
			end;
		end;
	end);
	client.Remote.Send("Session", l__SessionKey__2, "GetPeerList");
	local l__gTable__37 = v8.gTable;
	v8:Ready();
end;
