function methods.DoLockChatBar(J)if J.TextLabel then if LocalPlayer.UserId>0 then J.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 J.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 J:CalculateSize()end if J.TextBox then J.TextBox.Active=false J.TextBox.Focused:connect(function()J.TextBox:ReleaseFocus()end)end end function methods.SetUpTextBoxEvents(u,J,Y,U)for J,Y in pairs(u.TextBoxConnections)do Y:disconnect()u.TextBoxConnections[J]=nil end u.TextBoxConnections.UserInputBegan=UserInputService.InputBegan:connect(function(Y,U)if Y.KeyCode==Enum.KeyCode.Backspace then if u:IsFocused()and J.Text==""then u:SetChannelTarget(ChatSettings.GeneralChannelName)end end end)u.TextBoxConnections.TextBoxChanged=J.Changed:connect(function(Y)if Y=="\065\098\115\111\108\117\116\101\083\105\122\101"then u:CalculateSize()return end if Y~="\084\101\120\116"then return end u:CalculateSize()if string.len(J.Text)>ChatSettings.MaximumMessageLength then J.Text=string.sub(J.Text,1,ChatSettings.MaximumMessageLength)return end if not u.InCustomState then local Y=u.CommandProcessor:ProcessInProgressChatMessage(J.Text,u.ChatWindow,u)if Y then u.InCustomState=true u.CustomState=Y end else u.CustomState:TextUpdated()end end)local function e(U)if U or J.Text~=""then Y.Visible=false else Y.Visible=true end end u.TextBoxConnections.MessageModeClick=U.MouseButton1Click:connect(function()if U.Text~=""then u:SetChannelTarget(ChatSettings.GeneralChannelName)end end)u.TextBoxConnections.TextBoxFocused=J.Focused:connect(function()if not u.UserHasChatOff then u:CalculateSize()e(true)end end)u.TextBoxConnections.TextBoxFocusLost=J.FocusLost:connect(function(Y,U)u:CalculateSize()if U and U.KeyCode==Enum.KeyCode.Escape then J.Text=""end e(false)end)end function methods.GetTextBox(J)return J.TextBox end function methods.GetMessageModeTextButton(J)return J.GuiObjects.MessageModeTextButton end
-- Used to lock the chat bar when the user has chat turned off.
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
