local Y=require((game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")):WaitForChild("\078\101\118\101\114\109\111\114\101"))local w=Y("\113\071\085\073")local T=Y("\077\097\105\100")local t=Y("\077\097\116\104")local M={}M.ClassName="\083\110\097\099\107\098\097\114"M.__index=M M.Height=48 M.MinimumWidth=288 M.MaximumWidth=700 M.TextWidthOffset=24 M.Position=UDim2.new(1,-10,1,-10-M.Height)M.FadeTime=.16 M.CornerRadius=2 local p=Color3.fromRGB(78,205,196)function M.new(Y,t,f)local y=setmetatable({},M)local u=Instance.new("\073\109\097\103\101\066\117\116\116\111\110")u.ZIndex=7 u.Name="\083\110\097\099\107\098\097\114"u.Size=UDim2.new(0,100,0,y.Height)u.BorderSizePixel=0 u.BackgroundColor3=Color3.new(.196,.196,.196)u.Archivable=false u.ClipsDescendants=false u.Position=y.Position u.AutoButtonColor=false u.BackgroundTransparency=1 y.Gui=u y.BackgroundImages={w.BackWithRoundedRectangle(u,y.CornerRadius,u.BackgroundColor3)}local B=1 local Z=Instance.new("\070\114\097\109\101")Z.AnchorPoint=Vector2.new(.5,.5)Z.Parent=u Z.Name="\083\104\097\100\111\119\067\111\110\116\097\105\110\101\114"Z.BackgroundTransparency=1 Z.Size=UDim2.new(1,B*2,1,B*2)Z.Archivable=false Z.Position=UDim2.new(.5,0,.5,0)y.ShadowImages={w.AddNinePatch(Z,"\114\098\120\097\115\115\101\116\105\100\058\047\047\049\057\049\056\051\056\048\048\052",Vector2.new(150,150),y.CornerRadius+B,"\073\109\097\103\101\076\097\098\101\108")}for Y,w in pairs(y.ShadowImages)do w.ImageTransparency=.74 w.ZIndex=u.ZIndex-2 end for Y,w in pairs(y.BackgroundImages)do w.ZIndex=u.ZIndex-1 end local U=Instance.new("\084\101\120\116\076\097\098\101\108")U.Size=UDim2.new(1,-y.TextWidthOffset*2,0,16)U.Position=UDim2.new(0,y.TextWidthOffset,0,16)U.TextXAlignment=Enum.TextXAlignment.Left U.TextYAlignment=Enum.TextYAlignment.Center U.Name="\083\110\097\099\107\098\097\114\076\097\098\101\108"U.TextTransparency=.87 U.TextColor3=Color3.new(1,1,1)U.BackgroundTransparency=1 U.BorderSizePixel=0 U.Font=Enum.Font.SourceSans U.Text=t U.FontSize=Enum.FontSize.Size18 U.ZIndex=u.ZIndex-1 U.Parent=u y._textLabel=U y._whileActiveMaid=T.new()y.Gui.Parent=Y local X if f and f.CallToAction then if type(f.CallToAction)=="\115\116\114\105\110\103"then X=f.CallToAction else X=tostring(f.CallToAction.Text)end X=X:upper()local Y=Instance.new("\084\101\120\116\066\117\116\116\111\110")Y.Name="\067\097\108\108\084\111\065\099\116\105\111\110\066\117\116\116\111\110"Y.AnchorPoint=Vector2.new(1,.5)Y.BackgroundTransparency=1 Y.Position=UDim2.new(1,-y.TextWidthOffset,.5,0)Y.Size=UDim2.new(.5,0,.8,0)Y.Text=X Y.Font=Enum.Font.SourceSans Y.FontSize=U.FontSize Y.TextXAlignment=Enum.TextXAlignment.Right Y.TextColor3=p Y.ZIndex=u.ZIndex Y.Parent=u Y.Size=UDim2.new(UDim.new(0,Y.TextBounds.X),Y.Size.Y)y._whileActiveMaid:GiveTask(Y.MouseButton1Click:Connect(function()if f.CallToAction.OnClick then y:Dismiss()f.CallToAction.OnClick()end end))y._whileActiveMaid:GiveTask(Y.MouseEnter:Connect(function()Y.TextColor3=p:lerp(Color3.new(0,0,0),.2)end))y._whileActiveMaid:GiveTask(Y.MouseLeave:Connect(function()Y.TextColor3=p end))y._callToActionButton=Y end local d=y._textLabel.TextBounds.X+y.TextWidthOffset*2 if y._callToActionButton then d=(d+y._callToActionButton.Size.X.Offset)+y.TextWidthOffset*2 end if d<y.MinimumWidth then d=y.MinimumWidth elseif d>y.MaximumWidth then d=y.MaximumWidth end if X then y._textLabel.Text=t end y.Gui.Size=UDim2.new(0,d,0,y.Height)y.Position=y.Position+UDim2.new(0,-d,0,0)y.Gui.Position=y.Position y.AbsolutePosition=y.Gui.AbsolutePosition return y end function M.Dismiss(Y)error("\078\111\116 \105\109\112\108\101\109\101\110\116\101\100")end function M.SetBackgroundTransparency(w,Y)for w,T in pairs(w.BackgroundImages)do T.ImageTransparency=Y end for w,T in pairs(w.ShadowImages)do T.ImageTransparency=t.map(Y,0,1,.74,1)end end function M.FadeOutTransparency(T,Y)if Y then T:SetBackgroundTransparency(t.map(Y,0,1,0,1))T._textLabel.TextTransparency=t.map(Y,0,1,.13,1)if T._callToActionButton then T._callToActionButton.TextTransparency=Y end else local Y={ImageTransparency=1}for t,M in pairs(T.BackgroundImages)do w.TweenTransparency(M,Y,T.FadeTime,true)end for t,M in pairs(T.ShadowImages)do w.TweenTransparency(M,Y,T.FadeTime,true)end w.TweenTransparency(T._textLabel,{TextTransparency=1},T.FadeTime,true)if T._callToActionButton then w.TweenTransparency(T._callToActionButton,{TextTransparency=1},T.FadeTime,true)end end end function M.FadeInTransparency(T,Y)if Y then T:SetBackgroundTransparency(t.map(Y,0,1,1,0))T._textLabel.TextTransparency=t.map(Y,0,1,1,.13)if T._callToActionButton then T._callToActionButton.TextTransparency=Y end else do local Y={ImageTransparency=0}for t,M in pairs(T.BackgroundImages)do w.TweenTransparency(M,Y,T.FadeTime,true)end end do local Y={ImageTransparency=.74}for t,M in pairs(T.ShadowImages)do w.TweenTransparency(M,Y,T.FadeTime,true)end end w.TweenTransparency(T._textLabel,{TextTransparency=.13},T.FadeTime,true)if T._callToActionButton then w.TweenTransparency(T._callToActionButton,{TextTransparency=0},T.FadeTime,true)end end end function M.FadeHandler(t,Y,w,T)assert(Y,"\091\083\110\097\099\107\098\097\114\093 - \073\110\116\101\114\110\097\108 \102\117\110\099\116\105\111\110 \115\104\111\117\108\100 \110\111\116 \104\097\118\101 \098\101\101\110 \099\097\108\108\101\100\046 \077\105\115\115\105\110\103 \078\101\119\080\111\115\105\116\105\111\110")if T then t:FadeOutTransparency(w and 1 or nil)else t:FadeInTransparency(w and 1 or nil)end if w then t.Gui.Position=Y else t.Gui:TweenPosition(Y,"\073\110\079\117\116","\081\117\097\100",t.FadeTime,true)end end function M.FadeOutUp(w,Y)local T=w.Position+UDim2.new(0,0,0,-w.Gui.AbsoluteSize.Y)w:FadeHandler(T,Y,true)end function M.FadeOutDown(w,Y)local T=w.Position+UDim2.new(0,0,0,w.Gui.AbsoluteSize.Y)w:FadeHandler(T,Y,true)end function M.FadeOutRight(w,Y)local T=w.Position+UDim2.new(0,w.Gui.AbsoluteSize.X,0,0)w:FadeHandler(T,Y,true)end function M.FadeOutLeft(w,Y)local T=w.Position+UDim2.new(0,-w.Gui.AbsoluteSize.X,0,0)w:FadeHandler(T,Y,true)end function M.FadeIn(w,Y)w:FadeHandler(w.Position,Y,false)end return M
--- Snackbars provide lightweight feedback on an operation
-- at the base of the screen. They automatically disappear
-- after a timeout or user interaction. There can only be
-- one on the screen at a time.
-- @classmod Snackbar

local require = require(game:GetService("ReplicatedStorage"):WaitForChild("Nevermore"))

local qGUI = require("qGUI")
local Maid = require("Maid")
local Math = require("Math")

-- Base clase, not functional
local Snackbar = {}
Snackbar.ClassName = "Snackbar"
Snackbar.__index = Snackbar
Snackbar.Height = 48
Snackbar.MinimumWidth = 288 -- Taken from google material design
Snackbar.MaximumWidth = 700
Snackbar.TextWidthOffset = 24
Snackbar.Position = UDim2.new(1, -10, 1, -10 - Snackbar.Height)
Snackbar.FadeTime = 0.16
Snackbar.CornerRadius = 2--24

local DEFAULT_TEXT_COLOR = Color3.fromRGB(78, 205, 196)

function Snackbar.new(Parent, Text, options)
	local self = setmetatable({}, Snackbar)

	local Gui = Instance.new("ImageButton")
	Gui.ZIndex = 7
	Gui.Name = "Snackbar"
	Gui.Size = UDim2.new(0, 100, 0, self.Height)
	Gui.BorderSizePixel = 0
	Gui.BackgroundColor3 = Color3.new(0.196, 0.196, 0.196) -- Google design specifications
	Gui.Archivable = false
	Gui.ClipsDescendants = false
	Gui.Position = self.Position
	Gui.AutoButtonColor = false
	Gui.BackgroundTransparency = 1
	self.Gui = Gui

	self.BackgroundImages = {qGUI.BackWithRoundedRectangle(Gui, self.CornerRadius, Gui.BackgroundColor3)}

	local ShadowRadius = 1
	local ShadowContainer = Instance.new("Frame")
	ShadowContainer.AnchorPoint = Vector2.new(0.5, 0.5)
	ShadowContainer.Parent = Gui
	ShadowContainer.Name = "ShadowContainer"
	ShadowContainer.BackgroundTransparency = 1
	ShadowContainer.Size = UDim2.new(1, ShadowRadius*2, 1, ShadowRadius*2)
	ShadowContainer.Archivable = false
	ShadowContainer.Position = UDim2.new(0.5, 0, 0.5, 0)

	--- Image is blurred at
	self.ShadowImages = {
		qGUI.AddNinePatch(ShadowContainer, "rbxassetid://191838004",
			Vector2.new(150, 150),
			self.CornerRadius + ShadowRadius,
			"ImageLabel"
		)
	}

	for _, item in pairs(self.ShadowImages) do
		item.ImageTransparency = 0.74
		item.ZIndex = Gui.ZIndex - 2
	end

	for _, item in pairs(self.BackgroundImages) do
		item.ZIndex = Gui.ZIndex - 1
	end

	local TextLabel = Instance.new("TextLabel")
	TextLabel.Size = UDim2.new(1, -self.TextWidthOffset*2, 0, 16)
	TextLabel.Position = UDim2.new(0, self.TextWidthOffset, 0, 16)
	TextLabel.TextXAlignment = Enum.TextXAlignment.Left
	TextLabel.TextYAlignment = Enum.TextYAlignment.Center
	TextLabel.Name = "SnackbarLabel"
	TextLabel.TextTransparency = 0.87
	TextLabel.TextColor3 = Color3.new(1, 1, 1)
	TextLabel.BackgroundTransparency = 1
	TextLabel.BorderSizePixel = 0
	TextLabel.Font = Enum.Font.SourceSans
	TextLabel.Text = Text
	TextLabel.FontSize = Enum.FontSize.Size18
	TextLabel.ZIndex = Gui.ZIndex-1
	TextLabel.Parent = Gui
	self._textLabel = TextLabel

	self._whileActiveMaid = Maid.new()
	self.Gui.Parent = Parent

	local callToActionText
	if options and options.CallToAction then
		if type(options.CallToAction) == "string" then
			callToActionText = options.CallToAction
		else
			callToActionText = tostring(options.CallToAction.Text)
		end
		callToActionText = callToActionText:upper()

		local button = Instance.new("TextButton")
		button.Name = "CallToActionButton"
		button.AnchorPoint = Vector2.new(1, 0.5)
		button.BackgroundTransparency = 1
		button.Position = UDim2.new(1, -self.TextWidthOffset, 0.5, 0)
		button.Size = UDim2.new(0.5, 0, 0.8, 0)
		button.Text = callToActionText
		button.Font = Enum.Font.SourceSans
		button.FontSize = TextLabel.FontSize
		button.TextXAlignment = Enum.TextXAlignment.Right
		button.TextColor3 = DEFAULT_TEXT_COLOR
		button.ZIndex = Gui.ZIndex
		button.Parent = Gui

		-- Resize
		button.Size = UDim2.new(UDim.new(0, button.TextBounds.X), button.Size.Y)

		self._whileActiveMaid:GiveTask(button.MouseButton1Click:Connect(function()
			if options.CallToAction.OnClick then
				self:Dismiss()
				options.CallToAction.OnClick()
			end
		end))

		self._whileActiveMaid:GiveTask(button.MouseEnter:Connect(function()
			button.TextColor3 = DEFAULT_TEXT_COLOR:lerp(Color3.new(0, 0, 0), 0.2)
		end))

		self._whileActiveMaid:GiveTask(button.MouseLeave:Connect(function()
			button.TextColor3 = DEFAULT_TEXT_COLOR
		end))

		self._callToActionButton = button
	end


	local width = self._textLabel.TextBounds.X + self.TextWidthOffset*2
	if self._callToActionButton then
		width = width + self._callToActionButton.Size.X.Offset + self.TextWidthOffset*2
	end

	if width < self.MinimumWidth then
		width = self.MinimumWidth
	elseif width > self.MaximumWidth then
		width = self.MaximumWidth
	end

	if callToActionText then
		self._textLabel.Text = Text
	end

	self.Gui.Size = UDim2.new(0, width, 0, self.Height)

	self.Position = self.Position + UDim2.new(0, -width, 0, 0)
	self.Gui.Position = self.Position
	self.AbsolutePosition = self.Gui.AbsolutePosition

	return self
end

function Snackbar:Dismiss()
	error("Not implemented")
end

function Snackbar:SetBackgroundTransparency(Transparency)
	for _, item in pairs(self.BackgroundImages) do
		item.ImageTransparency = Transparency
	end
	for _, item in pairs(self.ShadowImages) do
		item.ImageTransparency = Math.map(Transparency, 0, 1, 0.74, 1)
	end
end

function Snackbar:FadeOutTransparency(PercentFaded)
	if PercentFaded then
		self:SetBackgroundTransparency(Math.map(PercentFaded, 0, 1, 0, 1))
		self._textLabel.TextTransparency = Math.map(PercentFaded, 0, 1, 0.13, 1)

		if self._callToActionButton then
			self._callToActionButton.TextTransparency = PercentFaded
		end
	else
		local newProperties = {
			ImageTransparency = 1;
		}

		for _, item in pairs(self.BackgroundImages) do
			qGUI.TweenTransparency(item, newProperties, self.FadeTime, true)
		end
		for _, item in pairs(self.ShadowImages) do
			qGUI.TweenTransparency(item, newProperties, self.FadeTime, true)
		end

		qGUI.TweenTransparency(self._textLabel, {
			TextTransparency = 1;
		}, self.FadeTime, true)

		if self._callToActionButton then
			qGUI.TweenTransparency(self._callToActionButton, {
				TextTransparency = 1;
			}, self.FadeTime, true)
		end
	end
end

--- Will animate unless given PercentFaded
function Snackbar:FadeInTransparency(PercentFaded)
	if PercentFaded then
		-- self.Gui.BackgroundTransparency = Math.map(PercentFaded, 0, 1, 1, 0)
		self:SetBackgroundTransparency(Math.map(PercentFaded, 0, 1, 1, 0))
		self._textLabel.TextTransparency = Math.map(PercentFaded, 0, 1, 1, 0.13)

		if self._callToActionButton then
			self._callToActionButton.TextTransparency = PercentFaded
		end
	else
		-- Should be an ease-in-out transparency fade.
		do
			local newProperties = {
				ImageTransparency = 0;
			}
			for _, item in pairs(self.BackgroundImages) do
				qGUI.TweenTransparency(item, newProperties, self.FadeTime, true)
			end
		end

		do
			local newProperties = {
				ImageTransparency = 0.74;
			}
			for _, item in pairs(self.ShadowImages) do
				qGUI.TweenTransparency(item, newProperties, self.FadeTime, true)
			end
		end

		qGUI.TweenTransparency(self._textLabel, {
			TextTransparency = 0.13;
		}, self.FadeTime, true)

		if self._callToActionButton then
			qGUI.TweenTransparency(self._callToActionButton, {
				TextTransparency = 0;
			}, self.FadeTime, true)
		end
	end
end

-- Utility function
function Snackbar:FadeHandler(NewPosition, DoNotAnimate, IsFadingOut)
	assert(NewPosition, "[Snackbar] - Internal function should not have been called. Missing NewPosition")

	if IsFadingOut then
		self:FadeOutTransparency(DoNotAnimate and 1 or nil)
	else
		self:FadeInTransparency(DoNotAnimate and 1 or nil)
	end

	if DoNotAnimate then
		self.Gui.Position = NewPosition
	else
		self.Gui:TweenPosition(NewPosition, "InOut", "Quad", self.FadeTime, true)
	end
end

function Snackbar:FadeOutUp(DoNotAnimate)
	local NewPosition = self.Position + UDim2.new(0, 0, 0, -self.Gui.AbsoluteSize.Y)
	self:FadeHandler(NewPosition, DoNotAnimate, true)
end

function Snackbar:FadeOutDown(DoNotAnimate)
	local NewPosition = self.Position + UDim2.new(0, 0, 0, self.Gui.AbsoluteSize.Y)
	self:FadeHandler(NewPosition, DoNotAnimate, true)
end

function Snackbar:FadeOutRight(DoNotAnimate)
	local NewPosition = self.Position + UDim2.new(0, self.Gui.AbsoluteSize.X, 0, 0)
	self:FadeHandler(NewPosition, DoNotAnimate, true)
end

function Snackbar:FadeOutLeft(DoNotAnimate)
	local NewPosition = self.Position + UDim2.new(0, -self.Gui.AbsoluteSize.X, 0, 0)
	self:FadeHandler(NewPosition, DoNotAnimate, true)
end

function Snackbar:FadeIn(DoNotAnimate)
	self:FadeHandler(self.Position, DoNotAnimate, false)
end

return Snackbar