function methods.DoLockChatBar(g)if g.TextLabel then if LocalPlayer.UserId>0 then g.TextLabel.Text=ChatLocalization:Get("\071\097\109\101\067\104\097\116\095\067\104\097\116\077\101\115\115\097\103\101\086\097\108\105\100\097\116\111\114\095\083\101\116\116\105\110\103\115\069\114\114\111\114","\084\111 \099\104\097\116 \105\110 \103\097\109\101\044 \116\117\114\110 \111\110 \099\104\097\116 \105\110 \121\111\117\114 \080\114\105\118\097\099\121 \083\101\116\116\105\110\103\115\046")else g.TextLabel.Text=ChatLocalization:Get("\071\097\109\101\067\104\097\116\095\083\119\097\108\108\111\119\071\117\101\115\116\067\104\097\116\095\077\101\115\115\097\103\101","\083\105\103\110 \117\112 \116\111 \099\104\097\116 \105\110 \103\097\109\101\046")end g:CalculateSize()end if g.TextBox then g.TextBox.Active=false g.TextBox.Focused:connect(function()g.TextBox:ReleaseFocus()end)end end function methods.SetUpTextBoxEvents(C,g,G,F)for g,G in pairs(C.TextBoxConnections)do G:disconnect()C.TextBoxConnections[g]=nil end C.TextBoxConnections.UserInputBegan=UserInputService.InputBegan:connect(function(G,F)if G.KeyCode==Enum.KeyCode.Backspace then if C:IsFocused()and g.Text==""then C:SetChannelTarget(ChatSettings.GeneralChannelName)end end end)C.TextBoxConnections.TextBoxChanged=g.Changed:connect(function(G)if G=="\065\098\115\111\108\117\116\101\083\105\122\101"then C:CalculateSize()return end if G~="\084\101\120\116"then return end C:CalculateSize()if string.len(g.Text)>ChatSettings.MaximumMessageLength then g.Text=string.sub(g.Text,1,ChatSettings.MaximumMessageLength)return end if not C.InCustomState then local G=C.CommandProcessor:ProcessInProgressChatMessage(g.Text,C.ChatWindow,C)if G then C.InCustomState=true C.CustomState=G end else C.CustomState:TextUpdated()end end)local function a(F)if F or g.Text~=""then G.Visible=false else G.Visible=true end end C.TextBoxConnections.MessageModeClick=F.MouseButton1Click:connect(function()if F.Text~=""then C:SetChannelTarget(ChatSettings.GeneralChannelName)end end)C.TextBoxConnections.TextBoxFocused=g.Focused:connect(function()if not C.UserHasChatOff then C:CalculateSize()a(true)end end)C.TextBoxConnections.TextBoxFocusLost=g.FocusLost:connect(function(G,F)C:CalculateSize()if F and F.KeyCode==Enum.KeyCode.Escape then g.Text=""end a(false)end)end function methods.GetTextBox(g)return g.TextBox end function methods.GetMessageModeTextButton(g)return g.GuiObjects.MessageModeTextButton end

function methods:DoLockChatBar()
	if self.TextLabel then
		if LocalPlayer.UserId > 0 then
			self.TextLabel.Text = ChatLocalization:Get(
				"GameChat_ChatMessageValidator_SettingsError",
				"To chat in game, turn on chat in your Privacy Settings."
			)
		else
			self.TextLabel.Text = ChatLocalization:Get(
				"GameChat_SwallowGuestChat_Message",
				"Sign up to chat in game."
			)
		end
		self:CalculateSize()
	end
	if self.TextBox then
		self.TextBox.Active = false
		self.TextBox.Focused:connect(function()
			self.TextBox:ReleaseFocus()
		end)
	end
end

function methods:SetUpTextBoxEvents(TextBox, TextLabel, MessageModeTextButton)
	-- Clean up events from a previous setup.
	for name, conn in pairs(self.TextBoxConnections) do
		conn:disconnect()
		self.TextBoxConnections[name] = nil
	end

	--// Code for getting back into general channel from other target channel when pressing backspace.
	self.TextBoxConnections.UserInputBegan = UserInputService.InputBegan:connect(function(inputObj, gpe)
		if (inputObj.KeyCode == Enum.KeyCode.Backspace) then
			if (self:IsFocused() and TextBox.Text == "") then
				self:SetChannelTarget(ChatSettings.GeneralChannelName)
			end
		end
	end)

	self.TextBoxConnections.TextBoxChanged = TextBox.Changed:connect(function(prop)
		if prop == "AbsoluteSize" then
			self:CalculateSize()
			return
		end

		if prop ~= "Text" then
			return
		end

		self:CalculateSize()

		if (string.len(TextBox.Text) > ChatSettings.MaximumMessageLength) then
			TextBox.Text = string.sub(TextBox.Text, 1, ChatSettings.MaximumMessageLength)
			return
		end

		if not self.InCustomState then
			local customState = self.CommandProcessor:ProcessInProgressChatMessage(TextBox.Text, self.ChatWindow, self)
			if customState then
				self.InCustomState = true
				self.CustomState = customState
			end
		else
			self.CustomState:TextUpdated()
		end
	end)

	local function UpdateOnFocusStatusChanged(isFocused)
		if isFocused or TextBox.Text ~= "" then
			TextLabel.Visible = false
		else
			TextLabel.Visible = true
		end
	end

	self.TextBoxConnections.MessageModeClick = MessageModeTextButton.MouseButton1Click:connect(function()
		if MessageModeTextButton.Text ~= "" then
			self:SetChannelTarget(ChatSettings.GeneralChannelName)
		end
	end)

	self.TextBoxConnections.TextBoxFocused = TextBox.Focused:connect(function()
		if not self.UserHasChatOff then
			self:CalculateSize()
			UpdateOnFocusStatusChanged(true)
		end
	end)

	self.TextBoxConnections.TextBoxFocusLost = TextBox.FocusLost:connect(function(enterPressed, inputObject)
		self:CalculateSize()
		if (inputObject and inputObject.KeyCode == Enum.KeyCode.Escape) then
			TextBox.Text = ""
		end
		UpdateOnFocusStatusChanged(false)
	end)
end

function methods:GetTextBox()
	return self.TextBox
end

function methods:GetMessageModeTextButton()
	return self.GuiObjects.MessageModeTextButton
end
