--// All global vars will be wiped/replaced except script
--// All guis are autonamed client.Variables.CodeName..gui.Name


return function(data)
	local color = data.Color
	local playergui = service.PlayerGui
	local localplayer = service.Players.LocalPlayer
	local mouse = localplayer:GetMouse()
	local gui = script.Parent.Parent
	
	if color=='off' then
		local guis = client.UI.Get("BChat")
		if guis then
			for i,v in pairs(guis) do
				if v ~= gui then
					v:Destroy()
				end
			end
			gui:Destroy()
		end
	else
		if playergui:FindFirstChild(gui.Name) then 
			playergui[gui.Name]:Destroy() 
		end
		
		local box = gui.Frame.Box
		local close = gui.Frame.Close
		
		box.Text='Click here or press ";" to chat'
		
		box.FocusLost:connect(function(enterPressed)
			if enterPressed and localplayer.Character:FindFirstChild('Head') and color and box.Text~='Click here or press ";" to chat' then
				service.ChatService:Chat(localplayer.Character.Head,service.LaxFilter(box.Text),color)
				box.Text='Click here or press ";" to chat'
			end
		end)
		
		mouse.KeyDown:connect(function(key)
			if key==';' then
				box:CaptureFocus()
			end
		end)
		
		close.MouseButton1Click:connect(function()
			gui:Destroy()
		end)
		
		gTable:Ready()
	end
end
