return function(b)local V=service.PlayerGui local r=service.Players.LocalPlayer local g=script.Parent.Parent local T=g.Frame local B=T.termCont local j=T.serverCont local e=T.localCont local d=T.logsCont local I=T.scriptCont local W=T.errorCont local m=T.localTab local U=T.scriptTab local E=T.logsTab local X=T.termTab local O=T.serverTab local n=T.errorTab local Z=g.Frame.Close local S=g.Frame.Command local z=g.Frame.Nameb local o=g.Frame.Dragger local J=g.Entry local t={}local Q={}local C={}local H={}local M={}local K={}local function l()e.Visible=true I.Visible=false d.Visible=false B.Visible=false j.Visible=false W.Visible=false m.BackgroundTransparency=0 U.BackgroundTransparency=.5 E.BackgroundTransparency=.5 X.BackgroundTransparency=.5 O.BackgroundTransparency=.5 n.BackgroundTransparency=.5 end local function F()e.Visible=false I.Visible=true d.Visible=false B.Visible=false j.Visible=false W.Visible=false m.BackgroundTransparency=.5 U.BackgroundTransparency=0 E.BackgroundTransparency=.5 X.BackgroundTransparency=.5 O.BackgroundTransparency=.5 n.BackgroundTransparency=.5 end local function A()e.Visible=false I.Visible=false d.Visible=true B.Visible=false j.Visible=false W.Visible=false m.BackgroundTransparency=.5 U.BackgroundTransparency=.5 E.BackgroundTransparency=0 X.BackgroundTransparency=.5 O.BackgroundTransparency=.5 n.BackgroundTransparency=.5 end local function v()e.Visible=false I.Visible=false d.Visible=false B.Visible=true j.Visible=false W.Visible=false m.BackgroundTransparency=.5 U.BackgroundTransparency=.5 E.BackgroundTransparency=.5 X.BackgroundTransparency=0 O.BackgroundTransparency=.5 n.BackgroundTransparency=.5 end local function k()e.Visible=false I.Visible=false d.Visible=false B.Visible=false j.Visible=true W.Visible=false m.BackgroundTransparency=.5 U.BackgroundTransparency=.5 E.BackgroundTransparency=.5 X.BackgroundTransparency=.5 O.BackgroundTransparency=0 n.BackgroundTransparency=.5 end local function f()e.Visible=false I.Visible=false d.Visible=false B.Visible=false j.Visible=false W.Visible=true m.BackgroundTransparency=.5 U.BackgroundTransparency=.5 E.BackgroundTransparency=.5 X.BackgroundTransparency=.5 O.BackgroundTransparency=.5 n.BackgroundTransparency=0 end local function L(b,V)b:ClearAllChildren()local r=0 for V,g in next,V do local T,B,j=J:Clone()if type(g)=="\116\097\098\108\101"then B=g.Text j=g.Color else B=tostring(g)end T.Visible=true T.Text=tostring(B)T.Position=UDim2.new(0,0,0,r*20)T.Parent=b T.TextColor3=j or T.TextColor3 r=r+1 end b.CanvasSize=UDim2.new(0,0,0,r*20)local g=r*20-b.AbsoluteWindowSize.Y if g<0 then g=0 end b.CanvasPosition=Vector2.new(0,g)end local function i()L(I,M)L(d,H)L(j,C)L(B,t)L(e,Q)L(W,K)end local function P(b,V)table.insert(V,b)if#V>500 then table.remove(V,1)end end local function a(b)local V={}for b,r in next,b do if type(r)=="\116\097\098\108\101"then local b,g=r.messageType if b=="\069\114\114\111\114"then g=Color3.new(1,0,0)elseif b=="\073\110\102\111"then g=Color3.new(0,0,1)elseif b=="\087\097\114\110\105\110\103"then g=Color3.new(0,1,1)end table.insert(V,{Text=r.message;Color=g})else table.insert(V,tostring(r))end end return V end local function G(b)local V={}for b,r in next,b do if type(r)=="\116\097\098\108\101"then table.insert(V,{Text=tostring(r.Text)..("\058 "..tostring(r.Desc))})else table.insert(V,tostring(r))end end return V end service.Events.TerminalLive:connect(function(b)local V=b.Data local r=b.Type P(V,t)L(B,t)end)local q=service.StartLoop("\084\101\114\109\105\110\097\108\076\111\111\112",1,function()service.Debounce("\095\084\069\082\077\073\078\065\076\095\085\080\068\065\084\073\078\071",function()local b=client.Remote.Get("\084\101\114\109\105\110\097\108\068\097\116\097")C=a(b.ServerLogs or{})H=G(b.AdminLogs or{})M=G(b.ScriptLogs or{})K=G(b.ErrorLogs or{})Q=a(service.LogService:GetLogHistory()or{})L(I,M)L(d,H)L(W,K)L(j,C)L(e,Q)end)end,true)S.FocusLost:connect(function(b)service.Debounce("\095\084\069\082\077\073\078\065\076\095\066\079\088\095\070\079\067\085\083\076\079\083\084",function()wait(.1)if b and S.Text~=""then local b=S.Text S.Text=""P("\062"..b,t)L(B,t)local V=client.Remote.Get("\084\101\114\109\105\110\097\108",b,{Time=tick()})if V and type(V)=="\116\097\098\108\101"then for b,V in next,V do P(V,t)end L(B,t)end S:CaptureFocus()S.Text=""end end)end)Z.MouseButton1Click:connect(function()q:Kill()client.Remote.Send("\083\101\115\115\105\111\110","\084\101\114\109\105\110\097\108",false)P("\068\105\115\099\111\110\110\101\099\116\105\110\103 \115\101\115\115\105\111\110\046\046\046",t)L(B,t)wait(.5)g:Destroy()end)m.MouseButton1Down:connect(l)U.MouseButton1Down:connect(F)E.MouseButton1Down:connect(A)X.MouseButton1Down:connect(v)O.MouseButton1Down:connect(k)n.MouseButton1Down:connect(f)local h=service.Players.LocalPlayer:GetMouse()local N,p=T.AbsoluteSize.X,T.AbsoluteSize.Y local s=false local R,u=N,p h.Move:connect(function(b,V)if s then N=R+(o.Position.X.Offset+20)p=u+(o.Position.Y.Offset+20)if N<300 then N=300 end if p<200 then p=200 end T.Size=UDim2.new(0,N,0,p)end end)o.DragBegin:connect(function(b)s=true T.Active=false end)o.DragStopped:connect(function(b,V)T.Active=true s=false R=N u=p o.Position=UDim2.new(1,-20,1,-20)i()end)i()gTable:Ready()end


return function(data)
	local playergui = service.PlayerGui
	local localplayer = service.Players.LocalPlayer
	local gui = script.Parent.Parent
	local frame = gui.Frame
	--local cont = gui.Frame.Container
	
	local termCont = frame.termCont
	local serverCont = frame.serverCont
	local localCont = frame.localCont
	local logsCont = frame.logsCont
	local scriptCont = frame.scriptCont
	local errorCont = frame.errorCont
	
	local localTab = frame.localTab
	local scriptTab = frame.scriptTab
	local logsTab = frame.logsTab
	local termTab = frame.termTab
	local serverTab = frame.serverTab
	local errorTab = frame.errorTab
	
	local close = gui.Frame.Close
	local box = gui.Frame.Command
	local name = gui.Frame.Nameb
	local dragger = gui.Frame.Dragger
	local entry = gui.Entry
	
	local termLines = {}
	local localLines = {}
	local serverLines = {}
	local logsLines = {}
	local scriptLines = {}
	local errorLines = {}
	
	local function openLocal()
		localCont.Visible = true
		scriptCont.Visible = false
		logsCont.Visible = false
		termCont.Visible = false
		serverCont.Visible = false
		errorCont.Visible = false
		
		localTab.BackgroundTransparency = 0
		scriptTab.BackgroundTransparency = 0.5
		logsTab.BackgroundTransparency = 0.5
		termTab.BackgroundTransparency = 0.5
		serverTab.BackgroundTransparency = 0.5
		errorTab.BackgroundTransparency = 0.5
	end
	
	local function openScript()
		localCont.Visible = false
		scriptCont.Visible = true
		logsCont.Visible = false
		termCont.Visible = false
		serverCont.Visible = false
		errorCont.Visible = false
		
		localTab.BackgroundTransparency = 0.5
		scriptTab.BackgroundTransparency = 0
		logsTab.BackgroundTransparency = 0.5
		termTab.BackgroundTransparency = 0.5
		serverTab.BackgroundTransparency = 0.5
		errorTab.BackgroundTransparency = 0.5
	end
	
	local function openLogs()
		localCont.Visible = false
		scriptCont.Visible = false
		logsCont.Visible = true
		termCont.Visible = false
		serverCont.Visible = false
		errorCont.Visible = false
		
		localTab.BackgroundTransparency = 0.5
		scriptTab.BackgroundTransparency = 0.5
		logsTab.BackgroundTransparency = 0
		termTab.BackgroundTransparency = 0.5
		serverTab.BackgroundTransparency = 0.5
		errorTab.BackgroundTransparency = 0.5
	end
	
	local function openTerm()
		localCont.Visible = false
		scriptCont.Visible = false
		logsCont.Visible = false
		termCont.Visible = true
		serverCont.Visible = false
		errorCont.Visible = false
		
		localTab.BackgroundTransparency = 0.5
		scriptTab.BackgroundTransparency = 0.5
		logsTab.BackgroundTransparency = 0.5
		termTab.BackgroundTransparency = 0
		serverTab.BackgroundTransparency = 0.5
		errorTab.BackgroundTransparency = 0.5
	end
	
	local function openServer()
		localCont.Visible = false
		scriptCont.Visible = false
		logsCont.Visible = false
		termCont.Visible = false
		serverCont.Visible = true
		errorCont.Visible = false
		
		localTab.BackgroundTransparency = 0.5
		scriptTab.BackgroundTransparency = 0.5
		logsTab.BackgroundTransparency = 0.5
		termTab.BackgroundTransparency = 0.5
		serverTab.BackgroundTransparency = 0
		errorTab.BackgroundTransparency = 0.5
	end
	
	local function openErrors()
		localCont.Visible = false
		scriptCont.Visible = false
		logsCont.Visible = false
		termCont.Visible = false
		serverCont.Visible = false
		errorCont.Visible = true
		
		localTab.BackgroundTransparency = 0.5
		scriptTab.BackgroundTransparency = 0.5
		logsTab.BackgroundTransparency = 0.5
		termTab.BackgroundTransparency = 0.5
		serverTab.BackgroundTransparency = 0.5
		errorTab.BackgroundTransparency = 0
	end
	
	local function populate(cont,lines)
		cont:ClearAllChildren()
		
		local num = 0
		for i,v in next,lines do
			local new,text,color = entry:Clone()
			
			if type(v) == "table" then
				text = v.Text
				color = v.Color
			else
				text = tostring(v)
			end			
			
			new.Visible = true
			new.Text = tostring(text)
			new.Position = UDim2.new(0,0,0,num*20)
			new.Parent = cont
			new.TextColor3 = color or new.TextColor3
			num = num+1
		end
		
		cont.CanvasSize = UDim2.new(0, 0, 0, (num*20))
		local glob = ((num*20) - cont.AbsoluteWindowSize.Y)
		if glob<0 then glob=0 end
		cont.CanvasPosition = Vector2.new(0,glob)
	end
	
	local function populateAll()
		populate(scriptCont,scriptLines)
		populate(logsCont,logsLines)
		populate(serverCont,serverLines)
		populate(termCont,termLines)
		populate(localCont,localLines)
		populate(errorCont,errorLines)
	end
	
	--name.Text = localplayer.userId.."@"..game.PlaceId.." ;/>"
	
	local function out(put,lines)
		table.insert(lines,put)
		if #lines>500 then
			table.remove(lines,1)
		end
	end
	
	local function formatOutput(tab)
		local new = {}
		for i,v in next,tab do
			if type(v) == "table" then
				local typ,color = v.messageType
				if typ == "Error" then
					color = Color3.new(1,0,0)
				elseif typ == "Info" then
					color = Color3.new(0,0,1)
				elseif typ == "Warning" then
					color = Color3.new(0,1,1)
				end
				
				table.insert(new,{
					Text = v.message;
					Color = color;
				})
			else
				table.insert(new,tostring(v))
			end
		end
		return new
	end
	
	local function formatLogs(tab)
		local new = {}
		for i,v in next,tab do
			if type(v) == "table" then
				table.insert(new,{
					Text = tostring(v.Text)..": "..tostring(v.Desc);
				})
			else
				table.insert(new,tostring(v))
			end
		end
		return new
	end
	
	service.Events.TerminalLive:connect(function(rData)
		local data = rData.Data
		local rType = rData.Type
		
		out(data,termLines)
		populate(termCont,termLines)
	end)
	
	local updater = service.StartLoop("TerminalLoop",1,function() 
		service.Debounce("_TERMINAL_UPDATING",function()
			local data = client.Remote.Get("TerminalData")
			
			--termLines = data.Output
			serverLines = formatOutput(data.ServerLogs or {})
			logsLines = formatLogs(data.AdminLogs or {})
			scriptLines = formatLogs(data.ScriptLogs or {})
			errorLines = formatLogs(data.ErrorLogs or {})
			localLines = formatOutput(service.LogService:GetLogHistory() or {})
			
			--populate(termCont,termLines)
			populate(scriptCont,scriptLines)
			populate(logsCont,logsLines)
			populate(errorCont,errorLines)
			populate(serverCont,serverLines)
			populate(localCont,localLines)
		end)
	end,true)
	
	box.FocusLost:connect(function(enterPressed)
		service.Debounce("_TERMINAL_BOX_FOCUSLOST",function()
			wait(0.1)
			if enterPressed and box.Text~="" then
				local com = box.Text
				box.Text = ""
				out(">"..com,termLines)
				populate(termCont,termLines)
				local ret = client.Remote.Get("Terminal",com,{
					Time = tick();
				})
				if ret and type(ret) == "table" then
					for i,ent in next,ret do
						out(ent,termLines)
					end
					populate(termCont,termLines)
				end
				box:CaptureFocus()
				box.Text = ""
			end
		end)
	end)
	
	close.MouseButton1Click:connect(function()
		updater:Kill()
		client.Remote.Send("Session","Terminal",false) 
		out("Disconnecting session...",termLines)
		populate(termCont,termLines)
		wait(0.5)
		gui:Destroy() 
	end)
	
	localTab.MouseButton1Down:connect(openLocal)
	scriptTab.MouseButton1Down:connect(openScript)
	logsTab.MouseButton1Down:connect(openLogs)
	termTab.MouseButton1Down:connect(openTerm)
	serverTab.MouseButton1Down:connect(openServer)
	errorTab.MouseButton1Down:connect(openErrors)
	
	local mouse=service.Players.LocalPlayer:GetMouse()
	local nx,ny=frame.AbsoluteSize.X,frame.AbsoluteSize.Y--500,300
	local dragging=false
	local defx,defy=nx,ny
	mouse.Move:connect(function(x,y) 
		if dragging then
			nx=defx+(dragger.Position.X.Offset+20)
			ny=defy+(dragger.Position.Y.Offset+20)
			if nx<300 then nx=300 end
			if ny<200 then ny=200 end
			frame.Size=UDim2.new(0, nx, 0, ny) 
		end
	end)
	dragger.DragBegin:connect(function(init)
		dragging = true
		frame.Active = false
	end)
	dragger.DragStopped:connect(function(x,y)
		frame.Active = true
		dragging = false
		defx = nx
		defy = ny
		dragger.Position = UDim2.new(1,-20,1,-20)
		populateAll()
	end)
	
	populateAll()
	gTable:Ready()
end
