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=game:GetService("\082\117\110\083\101\114\118\105\099\101")assert(w:IsClient())local T=Y("\068\114\097\103\103\097\098\108\101\083\110\097\099\107\098\097\114")local t={}function t.Init(w,Y)w._currentSnackbar=nil return w:WithScreenGui(Y)end function t.WithScreenGui(w,Y)w._screenGui=Y or error("\078\111 \115\099\114\101\101\110\071\117\105")return w end function t.MakeSnackbar(t,Y,w)assert(type(Y)=="\115\116\114\105\110\103","\116\101\120\116 \109\117\115\116 \098\101 \097 \115\116\114\105\110\103")local M=T.new(t._screenGui,Y,true,w)t:_showSnackbar(M)return M end function t._showSnackbar(w,Y)assert(Y,"\077\117\115\116 \115\101\110\100 \097 \115\110\097\099\107\098\097\114")if w._currentSnackbar==Y and w._currentSnackbar:IsVisible()then Y:Dismiss()else local T=false if w._currentSnackbar then if w._currentSnackbar:IsVisible()then w._currentSnackbar:Dismiss()w._currentSnackbar=nil T=true end end w._currentSnackbar=Y if T then delay(Y.FadeTime,function()if w._currentSnackbar==Y then Y:Show()end end)else Y:Show()end end end return t
--- Guarantees that only one snackbar is visible at once
-- @module SnackbarManager

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

local RunService = game:GetService("RunService")
assert(RunService:IsClient())

local DraggableSnackbar = require("DraggableSnackbar")

local SnackbarManager = {}

function SnackbarManager:Init(screenGui)
	self._currentSnackbar = nil
	return self:WithScreenGui(screenGui)
end

--- Sets the screenGui to use
function SnackbarManager:WithScreenGui(screenGui)
	self._screenGui = screenGui or error("No screenGui")

	return self
end

--- Automatically makes a snackbar and shows it
-- @param text to show
-- @param[opt] options
--[[
		If options are included, in this format, a call to action will be presented to the player
		options = {
			CallToAction = {
				Text = "Action";
				OnClick = function() end;
			};
		};
]]
function SnackbarManager:MakeSnackbar(text, options)
	assert(type(text) == "string", "text must be a string")

	local snackbar = DraggableSnackbar.new(self._screenGui, text, true, options)
	self:_showSnackbar(snackbar)

	return snackbar
end

--- Cleanup existing snackbar
function SnackbarManager:_showSnackbar(snackbar)
	assert(snackbar, "Must send a snackbar")

	if self._currentSnackbar == snackbar and self._currentSnackbar:IsVisible() then
		snackbar:Dismiss()
	else
		local dismissedSnackbar = false

		if self._currentSnackbar then
			if self._currentSnackbar:IsVisible() then
				self._currentSnackbar:Dismiss()
				self._currentSnackbar = nil
				dismissedSnackbar = true
			end
		end

		self._currentSnackbar = snackbar
		if dismissedSnackbar then
			delay(snackbar.FadeTime, function()
				if self._currentSnackbar == snackbar then
					snackbar:Show()
				end
			end)
		else
			snackbar:Show()
		end
	end
end

return SnackbarManager