--[[
	Creates a new alert in specified frame, of specified type. This will cause all existing alerts to move down, making room for the new one.
	The alert will disappear after a set time.
]]

function AlertController.addAlert(alerts, type, message)
	local entry = baseAlertElement:Clone()

	for _, child in pairs(alerts:GetChildren()) do
		if child:IsA("Frame") then
			child.LayoutOrder = child.LayoutOrder + 1
		end
	end

	local messageElement = entry.Message
	messageElement.Text = message

	if type == Constants.Alert.Fail then
		messageElement.TextColor3 = Color3.fromRGB(201, 67, 58)
	elseif type == Constants.Alert.Success then
		messageElement.TextColor3 = Color3.fromRGB(89, 156, 82)
	end

	entry.Parent = alerts

	delay(
		5,
		function()
			if messageElement and messageElement.Parent then
				local tween = TweenService:Create(messageElement, tweenInfo, {TextTransparency = 1})

				tween:Play()

				tween.Completed:Wait()

				entry:Destroy()
			end
		end
	)
end

return AlertController
