--///////////////////////// Constructors
--//////////////////////////////////////


function module.new()
	local obj = setmetatable({}, methods)
	obj.Destroyed = false

	local BaseFrame, Scroller, Layout = CreateGuiObjects()
	obj.GuiObject = BaseFrame
	obj.Scroller = Scroller
	obj.Layout = Layout

	obj.MessageObjectLog = {}

	obj.Name = "MessageLogDisplay"
	obj.GuiObject.Name = "Frame_" .. obj.Name

	obj.CurrentChannelName = ""

	obj.GuiObject:GetPropertyChangedSignal("AbsoluteSize"):Connect(function()
		spawn(function() obj:ReorderAllMessages() end)
	end)

	if FlagFixChatMessageLogPerformance then
		local wasScrolledDown = true

		obj.Layout:GetPropertyChangedSignal("AbsoluteContentSize"):Connect(function()
			local size = obj.Layout.AbsoluteContentSize
			obj.Scroller.CanvasSize = UDim2.new(0, 0, 0, size.Y)
			if wasScrolledDown then
				local windowSize = obj.Scroller.AbsoluteWindowSize
				obj.Scroller.CanvasPosition = Vector2.new(0, size.Y - windowSize.Y)
			end
		end)

		obj.Scroller:GetPropertyChangedSignal("CanvasPosition"):Connect(function()
			wasScrolledDown = obj:IsScrolledDown()
		end)
	end

	return obj
end

return module
