function methods.DoLockChatBar(Q)if Q.TextLabel then if LocalPlayer.UserId>0 then Q.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 Q.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 Q:CalculateSize()end if Q.TextBox then Q.TextBox.Active=false Q.TextBox.Focused:connect(function()Q.TextBox:ReleaseFocus()end)end end function methods.SetUpTextBoxEvents(V,Q,A,P)for Q,A in pairs(V.TextBoxConnections)do A:disconnect()V.TextBoxConnections[Q]=nil end V.TextBoxConnections.UserInputBegan=UserInputService.InputBegan:connect(function(A,P)if A.KeyCode==Enum.KeyCode.Backspace then if V:IsFocused()and Q.Text==""then V:SetChannelTarget(ChatSettings.GeneralChannelName)end end end)V.TextBoxConnections.TextBoxChanged=Q.Changed:connect(function(A)if A=="\065\098\115\111\108\117\116\101\083\105\122\101"then V:CalculateSize()return end if A~="\084\101\120\116"then return end V:CalculateSize()if FFlagUserChatNewMessageLengthCheck2 then if utf8.len(utf8.nfcnormalize(Q.Text))>ChatSettings.MaximumMessageLength then Q.Text=V.PreviousText else V.PreviousText=Q.Text end else if string.len(Q.Text)>ChatSettings.MaximumMessageLength then Q.Text=string.sub(Q.Text,1,ChatSettings.MaximumMessageLength)return end end if not V.InCustomState then local A=V.CommandProcessor:ProcessInProgressChatMessage(Q.Text,V.ChatWindow,V)if A then V.InCustomState=true V.CustomState=A end else V.CustomState:TextUpdated()end end)local function x(P)if P or Q.Text~=""then A.Visible=false else A.Visible=true end end V.TextBoxConnections.MessageModeClick=P.MouseButton1Click:connect(function()if P.Text~=""then V:SetChannelTarget(ChatSettings.GeneralChannelName)end end)V.TextBoxConnections.TextBoxFocused=Q.Focused:connect(function()if not V.UserHasChatOff then V:CalculateSize()x(true)end end)V.TextBoxConnections.TextBoxFocusLost=Q.FocusLost:connect(function(A,P)V:CalculateSize()if P and P.KeyCode==Enum.KeyCode.Escape then Q.Text=""end x(false)end)end function methods.GetTextBox(Q)return Q.TextBox end function methods.GetMessageModeTextButton(Q)return Q.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 FFlagUserChatNewMessageLengthCheck2 then
			if utf8.len(utf8.nfcnormalize(TextBox.Text)) > ChatSettings.MaximumMessageLength then
				TextBox.Text = self.PreviousText
			else
				self.PreviousText = TextBox.Text
			end
		else
			if string.len(TextBox.Text) > ChatSettings.MaximumMessageLength then
				TextBox.Text = string.sub(TextBox.Text, 1, ChatSettings.MaximumMessageLength)
				return
			end
		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
