function methods.GetMessageHeight(l,R,M,e)e=e or M.AbsoluteSize.X local r=l:GetStringTextBounds(R.Text,R.Font,R.TextSize,UDim2.new(0,e,0,1000))return r.Y end function methods.GetNumberOfSpaces(l,R,M,e)local r=l:GetStringTextBounds(R,M,e)local Z=l:GetStringTextBounds(" ",M,e)return math.ceil(r.X/Z.X)end function methods.CreateBaseMessage(r,R,M,e,l)local Z=r:GetFromObjectPool("\070\114\097\109\101")Z.Selectable=false Z.Size=UDim2.new(1,0,0,18)Z.Visible=true Z.BackgroundTransparency=1 local F=8 local P=r:GetFromObjectPool("\084\101\120\116\076\097\098\101\108")P.Selectable=false P.Size=UDim2.new(1,-(F+6),1,0)P.Position=UDim2.new(0,F,0,0)P.BackgroundTransparency=1 P.Font=M P.TextSize=e P.TextXAlignment=Enum.TextXAlignment.Left P.TextYAlignment=Enum.TextYAlignment.Top P.TextTransparency=0 P.TextStrokeTransparency=.625 P.TextStrokeColor3=Color3.new(1.0,.8078431372549,.95686274509804)P.TextColor3=l P.TextWrapped=true P.Text=R P.Visible=true P.Parent=Z return Z,P end function methods.AddNameButtonToBaseMessage(r,R,M,e,l)local Z=r:GetStringTextBounds(e,R.Font,R.TextSize)local F=r:GetFromObjectPool("\084\101\120\116\066\117\116\116\111\110")F.Selectable=false F.Size=UDim2.new(0,Z.X,0,Z.Y)F.Position=UDim2.new(0,0,0,0)F.BackgroundTransparency=1 F.Font=R.Font F.TextSize=R.TextSize F.TextXAlignment=R.TextXAlignment F.TextYAlignment=R.TextYAlignment F.TextTransparency=R.TextTransparency F.TextStrokeTransparency=R.TextStrokeTransparency F.TextStrokeColor3=Color3.new(.73725490196078,.14509803921569,.28235294117647)F.TextColor3=M F.Text=e F.Visible=true F.Parent=R F.MouseButton1Click:connect(function()r:NameButtonClicked(F,l)end)return F end function methods.AddChannelButtonToBaseMessage(r,R,M,e,l)local Z=r:GetStringTextBounds(e,R.Font,R.TextSize)local F=r:GetFromObjectPool("\084\101\120\116\066\117\116\116\111\110")F.Selectable=false F.Size=UDim2.new(0,Z.X,0,Z.Y)F.Position=UDim2.new(0,0,0,0)F.BackgroundTransparency=1 F.Font=R.Font F.TextSize=R.TextSize F.TextXAlignment=R.TextXAlignment F.TextYAlignment=R.TextYAlignment F.TextTransparency=R.TextTransparency F.TextStrokeTransparency=R.TextStrokeTransparency F.TextColor3=M F.Text=e F.Visible=true F.Parent=R F.MouseButton1Click:connect(function()r:ChannelButtonClicked(F,l)end)return F end function methods.NameButtonClicked(e,R,M)if not e.ChatWindow then return end if ChatSettings.ClickOnPlayerNameToWhisper then local R=Players:FindFirstChild(M)if R and R~=LocalPlayer then local R="\084\111 "..M if e.ChatWindow:GetChannel(R)then e.ChatBar:ResetCustomState()local M=e.ChatWindow:GetTargetMessageChannel()if M~=R then e.ChatWindow:SwitchCurrentChannel(R)end e.ChatBar:ResetText()e.ChatBar:CaptureFocus()elseif not e.ChatBar:IsInCustomState()then local R="\047\119 "..M e.ChatBar:CaptureFocus()e.ChatBar:SetText(R)end end end end function methods.ChannelButtonClicked(e,R,M)if not e.ChatWindow then return end if ChatSettings.ClickOnChannelNameToSetMainChannel then if e.ChatWindow:GetChannel(M)then e.ChatBar:ResetCustomState()local R=e.ChatWindow:GetTargetMessageChannel()if R~=M then e.ChatWindow:SwitchCurrentChannel(M)end e.ChatBar:ResetText()e.ChatBar:CaptureFocus()end end end function methods.RegisterChatWindow(M,R)M.ChatWindow=R M.ChatBar=R:GetChatBar()end function methods.GetFromObjectPool(M,R)if M.ObjectPool==nil then return Instance.new(R)end return M.ObjectPool:GetInstance(R)end function methods.RegisterObjectPool(M,R)M.ObjectPool=R end function methods.RegisterGuiRoot(M,R)testLabel.Parent=R end


function methods:GetMessageHeight(BaseMessage, BaseFrame, xSize)
	xSize = xSize or BaseFrame.AbsoluteSize.X
	local textBoundsSize = self:GetStringTextBounds(BaseMessage.Text, BaseMessage.Font, BaseMessage.TextSize, UDim2.new(0, xSize, 0, 1000))
	return textBoundsSize.Y
end

function methods:GetNumberOfSpaces(str, font, textSize)
	local strSize = self:GetStringTextBounds(str, font, textSize)
	local singleSpaceSize = self:GetStringTextBounds(" ", font, textSize)
	return math.ceil(strSize.X / singleSpaceSize.X)
end

function methods:CreateBaseMessage(message, font, textSize, chatColor)
	local BaseFrame = self:GetFromObjectPool("Frame")
	BaseFrame.Selectable = false
	BaseFrame.Size = UDim2.new(1, 0, 0, 18)
	BaseFrame.Visible = true
	BaseFrame.BackgroundTransparency = 1

	local messageBorder = 8

	local BaseMessage = self:GetFromObjectPool("TextLabel")
	BaseMessage.Selectable = false
	BaseMessage.Size = UDim2.new(1, -(messageBorder + 6), 1, 0)
	BaseMessage.Position = UDim2.new(0, messageBorder, 0, 0)
	BaseMessage.BackgroundTransparency = 1
	BaseMessage.Font = font
	BaseMessage.TextSize = textSize
	BaseMessage.TextXAlignment = Enum.TextXAlignment.Left
	BaseMessage.TextYAlignment = Enum.TextYAlignment.Top
	BaseMessage.TextTransparency = 0
	BaseMessage.TextStrokeTransparency = 0.625
	BaseMessage.TextStrokeColor3 = Color3.new( 255/255 , 206/255 , 244/255 )
	BaseMessage.TextColor3 = chatColor
	BaseMessage.TextWrapped = true
	BaseMessage.Text = message
	BaseMessage.Visible = true
	BaseMessage.Parent = BaseFrame

	return BaseFrame, BaseMessage
end

function methods:AddNameButtonToBaseMessage(BaseMessage, nameColor, formatName, playerName)
	local speakerNameSize = self:GetStringTextBounds(formatName, BaseMessage.Font, BaseMessage.TextSize)
	local NameButton = self:GetFromObjectPool("TextButton")
	NameButton.Selectable = false
	NameButton.Size = UDim2.new(0, speakerNameSize.X, 0, speakerNameSize.Y)
	NameButton.Position = UDim2.new(0, 0, 0, 0)
	NameButton.BackgroundTransparency = 1
	NameButton.Font = BaseMessage.Font
	NameButton.TextSize = BaseMessage.TextSize
	NameButton.TextXAlignment = BaseMessage.TextXAlignment
	NameButton.TextYAlignment = BaseMessage.TextYAlignment
	NameButton.TextTransparency = BaseMessage.TextTransparency
	NameButton.TextStrokeTransparency = BaseMessage.TextStrokeTransparency
	NameButton.TextStrokeColor3 = Color3.new( 188/255 , 37/255 , 72/255 )
	NameButton.TextColor3 = nameColor
	NameButton.Text = formatName
	NameButton.Visible = true
	NameButton.Parent = BaseMessage

	NameButton.MouseButton1Click:connect(function()
		self:NameButtonClicked(NameButton, playerName)
	end)

	return NameButton
end

function methods:AddChannelButtonToBaseMessage(BaseMessage, channelColor, formatChannelName, channelName)
	local channelNameSize = self:GetStringTextBounds(formatChannelName, BaseMessage.Font, BaseMessage.TextSize)
	local ChannelButton = self:GetFromObjectPool("TextButton")
	ChannelButton.Selectable = false
	ChannelButton.Size = UDim2.new(0, channelNameSize.X, 0, channelNameSize.Y)
	ChannelButton.Position = UDim2.new(0, 0, 0, 0)
	ChannelButton.BackgroundTransparency = 1
	ChannelButton.Font = BaseMessage.Font
	ChannelButton.TextSize = BaseMessage.TextSize
	ChannelButton.TextXAlignment = BaseMessage.TextXAlignment
	ChannelButton.TextYAlignment = BaseMessage.TextYAlignment
	ChannelButton.TextTransparency = BaseMessage.TextTransparency
	ChannelButton.TextStrokeTransparency = BaseMessage.TextStrokeTransparency
	ChannelButton.TextColor3 = channelColor
	ChannelButton.Text = formatChannelName
	ChannelButton.Visible = true
	ChannelButton.Parent = BaseMessage

	ChannelButton.MouseButton1Click:connect(function()
		self:ChannelButtonClicked(ChannelButton, channelName)
	end)

	return ChannelButton
end

function methods:NameButtonClicked(nameButton, playerName)
	if not self.ChatWindow then
		return
	end

	if ChatSettings.ClickOnPlayerNameToWhisper then
		local player = Players:FindFirstChild(playerName)
		if player and player ~= LocalPlayer then
			local whisperChannel = "To " ..playerName
			if self.ChatWindow:GetChannel(whisperChannel) then
				self.ChatBar:ResetCustomState()
				local targetChannelName = self.ChatWindow:GetTargetMessageChannel()
				if targetChannelName ~= whisperChannel then
					self.ChatWindow:SwitchCurrentChannel(whisperChannel)
				end
				self.ChatBar:ResetText()
				self.ChatBar:CaptureFocus()
			elseif not self.ChatBar:IsInCustomState() then
				local whisperMessage = "/w " ..playerName
				self.ChatBar:CaptureFocus()
				self.ChatBar:SetText(whisperMessage)
			end
		end
	end
end

function methods:ChannelButtonClicked(channelButton, channelName)
	if not self.ChatWindow then
		return
	end

	if ChatSettings.ClickOnChannelNameToSetMainChannel then
		if self.ChatWindow:GetChannel(channelName) then
			self.ChatBar:ResetCustomState()
			local targetChannelName = self.ChatWindow:GetTargetMessageChannel()
			if targetChannelName ~= channelName then
				self.ChatWindow:SwitchCurrentChannel(channelName)
			end
			self.ChatBar:ResetText()
			self.ChatBar:CaptureFocus()
		end
	end
end

function methods:RegisterChatWindow(chatWindow)
	self.ChatWindow = chatWindow
	self.ChatBar = chatWindow:GetChatBar()
end

function methods:GetFromObjectPool(className)
	if self.ObjectPool == nil then
		return Instance.new(className)
	end
	return self.ObjectPool:GetInstance(className)
end

function methods:RegisterObjectPool(objectPool)
	self.ObjectPool = objectPool
end

function methods:RegisterGuiRoot(root)
	testLabel.Parent = root
end
