return function(n,F)if F then setfenv(1,F)end local C local a=client.UI.Make("\087\105\110\100\111\119",{Name="\065\108\105\097\115\101\115",Title="\065\108\105\097\115 \069\100\105\116\111\114";Size={420,240},AllowMultiple=false})local E={Alias="",Args={Names={};Defaults={}},Command="";Description=""}for F,C in pairs(E)do if not n[F]then n[F]=C end end if a then local F=a:Add("\083\099\114\111\108\108\105\110\103\070\114\097\109\101",{BackgroundColor3=(Color3.fromRGB(31,31,31)):lerp(Color3.new(1,1,1),.2);Size=UDim2.new(1,-10,1,-10);Position=UDim2.new(0,5,0,5)})local E=F:Add("\083\099\114\111\108\108\105\110\103\070\114\097\109\101",{Size=UDim2.new(1,-10,1,-35),Position=UDim2.new(0,5,0,5),BackgroundTransparency=.5})local l local O,i,f local A A=a:Add("\070\114\097\109\101",{Visible=false;Size=UDim2.new(0,200,0,150),Position=UDim2.new(.5,-100,.5,-75);Children={{Class="\084\101\120\116\076\097\098\101\108",Text="\065\114\103\117\109\101\110\116 \078\097\109\101\058",Position=UDim2.new(0,0,0,10),Size=UDim2.new(1,0,0,20),BackgroundTransparency=1},{Class="\084\101\120\116\076\097\098\101\108",Text="\068\101\102\097\117\108\116\058",Position=UDim2.new(0,0,0,65);Size=UDim2.new(1,0,0,20),BackgroundTransparency=1},{Class="\084\101\120\116\066\117\116\116\111\110";Text="\083\097\118\101",Position=UDim2.new(.5,0,1,-30),Size=UDim2.new(.5,-20,0,20),BackgroundTransparency=1,OnClicked=function()if f==0 then table.insert(n.Args.Names,O)table.insert(n.Args.Defaults,i or"")else n.Args.Names[f]=O n.Args.Defaults[f]=i or""end l()O=nil i=nil A.Visible=false end}}})local g=A:Add({Class="\084\101\120\116\066\117\116\116\111\110",Text="\082\101\109\111\118\101",Position=UDim2.new(0,10,1,-30),Size=UDim2.new(.5,-20,0,20),BackgroundTransparency=1;OnClicked=function()if f~=0 then table.remove(n.Args.Names,f)table.remove(n.Args.Defaults,f)end l()O=nil i=nil A.Visible=false end})local p=A:Add("\084\101\120\116\066\111\120",{Text=O or"\110\097\109\101",Position=UDim2.new(0,10,0,35);Size=UDim2.new(1,-20,0,20),TextChanged=function(n,F,C)O=n end})local G=A:Add("\084\101\120\116\066\111\120",{Text=i or"";Position=UDim2.new(0,10,0,90),Size=UDim2.new(1,-20,0,20),TextChanged=function(n,F,C)i=n end})A.BackgroundColor3=A.BackgroundColor3:lerp(Color3.new(1,1,1),.05)p.BackgroundColor3=p.BackgroundColor3:lerp(Color3.new(1,1,1),.1)G.BackgroundColor3=p.BackgroundColor3 local function T(n)if not A.Visible then if n then O=n.Name i=n.Default end if f==0 then g.Text="\067\097\110\099\101\108"else g.Text="\082\101\109\111\118\101"end p.Text=O or"\110\097\109\101"G.Text=i or""A.Visible=true end end function l()E:ClearAllChildren()local C=1 E:Add("\084\101\120\116\076\097\098\101\108",{Text="  \065\108\105\097\115\058 ",ToolTip="\083\101\116 \116\104\101 \097\108\105\097\115 \065\100\111\110\105\115 \115\104\111\117\108\100 \099\104\101\099\107 \102\111\114 \105\110 \099\104\097\116";BackgroundTransparency=C%2==0 and 0 or.2,Size=UDim2.new(1,-10,0,30);Position=UDim2.new(0,5,0,30*(C-1)+5);TextXAlignment="\076\101\102\116";Children={[n.ExistingAlias and"\084\101\120\116\076\097\098\101\108"or"\084\101\120\116\066\111\120"]={Text=n.Alias or"";Size=UDim2.new(0,200,1,0);Position=UDim2.new(1,-200,0,0);BackgroundTransparency=1;TextChanged=not n.ExistingAlias and function(F,C,a)n.Alias=F end or nil}}})C=C+1 E:Add("\084\101\120\116\076\097\098\101\108",{Text="  \067\111\109\109\097\110\100\058 ",ToolTip="\083\101\116 \116\104\101 \099\111\109\109\097\110\100\040\115\041 \065\100\111\110\105\115 \115\104\111\117\108\100 \101\120\101\099\117\116\101 \119\104\101\110 \102\105\110\100\105\110\103 \116\104\101 \097\108\105\097\115",BackgroundTransparency=C%2==0 and 0 or.2,Size=UDim2.new(1,-10,0,30),Position=UDim2.new(0,5,0,30*(C-1)+5);TextXAlignment="\076\101\102\116";Children={TextBox={Text=n.Command or"",Size=UDim2.new(0,200,1,0);Position=UDim2.new(1,-200,0,0),BackgroundTransparency=1,TextChanged=function(F,C,a)n.Command=F end}}})C=C+1 E:Add("\084\101\120\116\076\097\098\101\108",{Text="  \068\101\115\099\114\105\112\116\105\111\110\058 ";ToolTip="\087\104\097\116 \100\111\101\115 \116\104\101 \097\108\105\097\115 \100\111\063";BackgroundTransparency=C%2==0 and 0 or.2,Size=UDim2.new(1,-10,0,30),Position=UDim2.new(0,5,0,30*(C-1)+5);TextXAlignment="\076\101\102\116";Children={TextBox={Text=n.Description or"",Size=UDim2.new(0,200,1,0),Position=UDim2.new(1,-200,0,0);BackgroundTransparency=1,TextChanged=function(F,C,a)n.Description=F end}}})C=C+2 E:Add("\084\101\120\116\066\117\116\116\111\110",{Text="\065\100\100 \065\114\103\117\109\101\110\116";BackgroundTransparency=C%2==0 and 0 or.2,Size=UDim2.new(1,-10,0,30);Position=UDim2.new(0,5,0,30*(C-1)+5),OnClicked=function(n)f=0 T()end})for F,a in ipairs(n.Args.Names)do C=C+1 E:Add("\084\101\120\116\066\117\116\116\111\110",{Text="\065\114\103\117\109\101\110\116\058 "..(a..(" \124 \068\101\102\097\117\108\116\058 "..n.Args.Defaults[F]));BackgroundTransparency=C%2==0 and 0 or.2,Size=UDim2.new(1,-10,0,30);Position=UDim2.new(0,5,0,30*(C-1)+5);OnClicked=function(C)f=F T({Name=a,Default=n.Args.Defaults[F]})end})end E:ResizeCanvas(false,true,false,false,5,5)F:Add("\084\101\120\116\066\117\116\116\111\110",{Text="\067\097\110\099\101\108";Position=UDim2.new(0,5,1,-25);Size=UDim2.new(.33333333333333,-8,0,20),OnClicked=function(n)a:Close()end})F:Add("\084\101\120\116\066\117\116\116\111\110",{Text="\082\101\109\111\118\101";Position=UDim2.new(.33333333333333,3,1,-25);Size=UDim2.new(.33333333333333,-7,0,20);OnClicked=function(F)if n.ExistingAlias then client.Functions.RemoveAlias(n.Alias)client.UI.Remove("\085\115\101\114\080\097\110\101\108")client.UI.Make("\085\115\101\114\080\097\110\101\108",{Tab="\065\108\105\097\115\101\115"})end a:Close()end})F:Add("\084\101\120\116\066\117\116\116\111\110",{Text="\083\097\118\101";Position=UDim2.new(.66666666666667,3,1,-25);Size=UDim2.new(.33333333333333,-8,0,20);OnClicked=function(F)if n.Alias==""or n.Command==""then client.UI.Make("\079\117\116\112\117\116",{Message="\065 \114\101\113\117\105\114\101\100 \102\105\101\108\100 \105\115 \109\105\115\115\105\110\103\033"})else client.Functions.SetAlias(n.Alias,n)client.UI.Remove("\085\115\101\114\080\097\110\101\108")client.UI.Make("\085\115\101\114\080\097\110\101\108",{Tab="\065\108\105\097\115\101\115"})a:Close()end end})end l()C=a.gTable a:Ready()end end


return function(data, env)
	if env then
		setfenv(1, env)
	end
	
	local gTable
	
	local window = client.UI.Make("Window",{
		Name  = "Aliases";
		Title = "Alias Editor";
		Size  = {420, 240};
		AllowMultiple = false;
	})

	local template =  {
		Alias = "",
		Args = {Names = {}, Defaults = {}},
		Command = "",
		Description = ""
	}
	for i,v in pairs(template) do
		if not data[i] then
			data[i] = v
		end
	end

	if window then
		local bg = window:Add("ScrollingFrame", {
			BackgroundColor3 = Color3.fromRGB(31, 31, 31):lerp(Color3.new(1,1,1), 0.2);
			Size = UDim2.new(1, -10, 1, -10);
			Position = UDim2.new(0, 5, 0, 5)
		})

		local content = bg:Add("ScrollingFrame", {
			Size = UDim2.new(1, -10, 1, -35);
			Position = UDim2.new(0, 5, 0, 5);
			BackgroundTransparency = 0.5;
		})

		local draw;
		local curArgName, curArgDefault, argIndex;
		local argBox; argBox = window:Add("Frame", {
			Visible = false;
			Size = UDim2.new(0, 200, 0, 150);
			Position = UDim2.new(0.5, -100, 0.5, -75);
			Children = {
				{
					Class = "TextLabel";
					Text = "Argument Name:";
					Position = UDim2.new(0, 0, 0, 10);
					Size = UDim2.new(1, 0, 0, 20);
					BackgroundTransparency = 1;
				};
				{
					Class = "TextLabel";
					Text = "Default:";
					Position = UDim2.new(0, 0, 0, 65);
					Size = UDim2.new(1, 0, 0, 20);
					BackgroundTransparency = 1;
				};
				{
					Class = "TextButton";
					Text = "Save";
					Position = UDim2.new(0.5, 0, 1, -30);
					Size = UDim2.new(0.5, -20, 0, 20);
					BackgroundTransparency = 1;
					OnClicked = function()
						if argIndex == 0 then
							table.insert(data.Args.Names, curArgName)
							table.insert(data.Args.Defaults, curArgDefault or "")
						else
							data.Args.Names[argIndex] = curArgName
							data.Args.Defaults[argIndex] = curArgDefault or ""
						end
						draw()
						curArgName = nil
						curArgDefault = nil
						argBox.Visible = false
					end
				};
			}
		})

		local endBtn = argBox:Add({
			Class = "TextButton";
			Text = "Remove";
			Position = UDim2.new(0, 10, 1, -30);
			Size = UDim2.new(0.5, -20, 0, 20);
			BackgroundTransparency = 1;
			OnClicked = function()
				if argIndex ~= 0 then
					table.remove(data.Args.Names, argIndex)
					table.remove(data.Args.Defaults, argIndex)
				end
				draw()
				curArgName = nil
				curArgDefault = nil
				argBox.Visible = false
			end
		})

		local argNameBox = argBox:Add("TextBox", {
			Text = curArgName or "name";
			Position = UDim2.new(0, 10, 0, 35);
			Size = UDim2.new(1, -20, 0, 20);
			TextChanged = function(newText, enter, box)
				curArgName = newText
			end
		});

		local argDefaultBox = argBox:Add("TextBox", {
			Text = curArgDefault or "";
			Position = UDim2.new(0, 10, 0, 90);
			Size = UDim2.new(1, -20, 0, 20);
			TextChanged = function(newText, enter, box)
				curArgDefault = newText
			end
		});

		argBox.BackgroundColor3 = argBox.BackgroundColor3:lerp(Color3.new(1, 1, 1), 0.05)
		argNameBox.BackgroundColor3 = argNameBox.BackgroundColor3:lerp(Color3.new(1, 1, 1), 0.1)
		argDefaultBox.BackgroundColor3 = argNameBox.BackgroundColor3

		local function showArgBox(argData)
			if not argBox.Visible then
				if argData then
					curArgName = argData.Name
					curArgDefault = argData.Default
				end
				if argIndex == 0 then
					endBtn.Text = "Cancel"
				else
					endBtn.Text = "Remove"
				end
				argNameBox.Text = curArgName or "name"
				argDefaultBox.Text = curArgDefault or ""
				argBox.Visible = true
			end
		end

		function draw()
			content:ClearAllChildren();

			local i = 1
			content:Add("TextLabel", {
				Text = "  ".."Alias"..": ";
				ToolTip = "Set the alias Adonis should check for in chat";
				BackgroundTransparency = (i%2 == 0 and 0) or 0.2;
				Size = UDim2.new(1, -10, 0, 30);
				Position = UDim2.new(0, 5, 0, (30*(i-1))+5);
				TextXAlignment = "Left";
				Children = {
					[data.ExistingAlias and "TextLabel" or "TextBox"] = {
						Text = data.Alias or "";
						Size = UDim2.new(0, 200, 1, 0);
						Position = UDim2.new(1, -200, 0, 0); 
						BackgroundTransparency = 1;
						TextChanged = not data.ExistingAlias and function(text, enter, new)
							data.Alias = text
						end or nil
					}
				}
			})
			i = i + 1
			content:Add("TextLabel", {
				Text = "  ".."Command"..": ";
				ToolTip = "Set the command(s) Adonis should execute when finding the alias";
				BackgroundTransparency = (i%2 == 0 and 0) or 0.2;
				Size = UDim2.new(1, -10, 0, 30);
				Position = UDim2.new(0, 5, 0, (30*(i-1))+5);
				TextXAlignment = "Left";
				Children = {
					TextBox = {
						Text = data.Command or "";
						Size = UDim2.new(0, 200, 1, 0);
						Position = UDim2.new(1, -200, 0, 0); 
						BackgroundTransparency = 1;
						TextChanged = function(text, enter, new)
							data.Command = text
						end
					}
				}
			})
			i = i + 1
			content:Add("TextLabel", {
				Text = "  ".."Description"..": ";
				ToolTip = "What does the alias do?";
				BackgroundTransparency = (i%2 == 0 and 0) or 0.2;
				Size = UDim2.new(1, -10, 0, 30);
				Position = UDim2.new(0, 5, 0, (30*(i-1))+5);
				TextXAlignment = "Left";
				Children = {
					TextBox = {
						Text = data.Description or "";
						Size = UDim2.new(0, 200, 1, 0);
						Position = UDim2.new(1, -200, 0, 0); 
						BackgroundTransparency = 1;
						TextChanged = function(text, enter, new)
							data.Description = text
						end
					}
				}
			})
			i = i + 2
			content:Add("TextButton", {
				Text = "Add Argument",
				BackgroundTransparency = (i%2 == 0 and 0) or 0.2;
				Size = UDim2.new(1, -10, 0, 30);
				Position = UDim2.new(0, 5, 0, (30*(i-1))+5);
				OnClicked = function(button)
					argIndex = 0
					showArgBox()
				end
			})
			for index,arg in ipairs(data.Args.Names) do
				i = i + 1
				content:Add("TextButton", {
					Text = "Argument: ".. arg .." | Default: "..data.Args.Defaults[index];
					BackgroundTransparency = (i%2 == 0 and 0) or 0.2;
					Size = UDim2.new(1, -10, 0, 30);
					Position = UDim2.new(0, 5, 0, (30*(i-1))+5);
					OnClicked = function(button)
						argIndex = index
						showArgBox({Name = arg, Default = data.Args.Defaults[index]})
					end
				})
			end

			content:ResizeCanvas(false, true, false, false, 5, 5)

			bg:Add("TextButton", {
				Text = "Cancel";
				Position = UDim2.new(0, 5, 1, -25);
				Size = UDim2.new(1/3, -8, 0, 20);
				OnClicked = function(button)
					window:Close()
				end
			})

			bg:Add("TextButton", {
				Text = "Remove";
				Position = UDim2.new(1/3, 3, 1, -25);
				Size = UDim2.new(1/3, -7, 0, 20);
				OnClicked = function(button)
					if data.ExistingAlias then
						client.Functions.RemoveAlias(data.Alias)
						client.UI.Remove("UserPanel")
						client.UI.Make("UserPanel", {Tab = "Aliases"})
					end
					window:Close()
				end
			})

			bg:Add("TextButton", {
				Text = "Save";
				Position = UDim2.new(2/3, 3, 1, -25);
				Size = UDim2.new(1/3, -8, 0, 20);
				OnClicked = function(button)
					if data.Alias == "" or data.Command == "" then
						client.UI.Make("Output", {Message = "A required field is missing!"})
					else
						client.Functions.SetAlias(data.Alias, data)
						client.UI.Remove("UserPanel")
						client.UI.Make("UserPanel", {Tab = "Aliases"})
						window:Close()
					end
				end
			})
		end

		draw()
		gTable = window.gTable
		window:Ready()
	end
end
