local N=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 C=N("\077\097\105\100")local F=N("\066\117\116\116\111\110\085\116\105\108\115")local h={}function h.Add(C,N)assert(N)assert(not N.GetMouseOverColor)N.GetMouseOverBoolValue=C.GetMouseOverBoolValue N.AddMouseOverEffect=C.AddMouseOverEffect N._getMouseOverTweenProperties=C._getMouseOverTweenProperties end function h.GetMouseOverBoolValue(F,N)local h=C.new()local d=Instance.new("\066\111\111\108\086\097\108\117\101")d.Value=false h:GiveTask(d)h:GiveTask(N.InputBegan:Connect(function(F)if F.UserInputType==Enum.UserInputType.MouseMovement then d.Value=true elseif F.UserInputType==Enum.UserInputType.Touch then local K=C.new()h[F]=K K:GiveTask(N.InputEnded:Connect(function(N)if N==F then h[F]=nil d.Value=false end end))delay(.2,function()if h[F]then d.Value=true end end)end end))h:GiveTask(N.InputEnded:Connect(function(N)if N.UserInputType==Enum.UserInputType.MouseMovement then d.Value=false end end))return h,d end function h._getMouseOverTweenProperties(C,N)if N:IsA("\073\109\097\103\101\066\117\116\116\111\110")then return{ImageColor3=F.GetMouseOverColor(N.ImageColor3);BackgroundColor3=F.GetMouseOverColor(N.BackgroundColor3)}else return{BackgroundColor3=F.GetMouseOverColor(N.BackgroundColor3)}end end function h.AddMouseOverEffect(h,N,C)C=C or F._getMouseOverTweenProperties(N)if N:IsA("\071\117\105\066\117\116\116\111\110")then N.AutoButtonColor=false end local d,K=F.GetMouseOverBoolValue(N)local a={}for C,F in pairs(C)do a[C]=N[C]end local function I()for C,F in pairs(K.Value and C or a)do N[C]=F end end I()d:GiveTask(K.Changed:Connect(I))h._maid[K]=d return K end return h
--- Mouse over mixin for general utility button mouse over effects
-- @module MouseOverMixin

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

local Maid = require("Maid")
local ButtonUtils = require("ButtonUtils")

local MouseOverMixin = {}

function MouseOverMixin:Add(class)
	assert(class)
	assert(not class.GetMouseOverColor)

	class.GetMouseOverBoolValue = self.GetMouseOverBoolValue
	class.AddMouseOverEffect = self.AddMouseOverEffect
	class._getMouseOverTweenProperties = self._getMouseOverTweenProperties
end

function MouseOverMixin:GetMouseOverBoolValue(gui)
	local maid = Maid.new()

	local mouseOver = Instance.new("BoolValue")
	mouseOver.Value = false
	maid:GiveTask(mouseOver)

	maid:GiveTask(gui.InputBegan:Connect(function(inputObject)
		if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
			mouseOver.Value = true
		elseif inputObject.UserInputType == Enum.UserInputType.Touch then
			-- Touch and hold counts as mouse over
			local touchMaid = Maid.new()
			maid[inputObject] = touchMaid

			touchMaid:GiveTask(gui.InputEnded:Connect(function(endInputObject)
				if endInputObject == inputObject then
					maid[inputObject] = nil
					mouseOver.Value = false
				end
			end))

			delay(0.2, function()
				if maid[inputObject] then
					mouseOver.Value = true
				end
			end)
		end
	end))

	maid:GiveTask(gui.InputEnded:Connect(function(inputObject)
		if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
			mouseOver.Value = false
		end
	end))

	return maid, mouseOver
end

function MouseOverMixin:_getMouseOverTweenProperties(gui)
	if gui:IsA("ImageButton") then
		return {
			ImageColor3 = ButtonUtils.GetMouseOverColor(gui.ImageColor3);
			BackgroundColor3 = ButtonUtils.GetMouseOverColor(gui.BackgroundColor3);
		}
	else
		return {
			BackgroundColor3 = ButtonUtils.GetMouseOverColor(gui.BackgroundColor3);
		}
	end
end

function MouseOverMixin:AddMouseOverEffect(gui, tweenProperties)
	tweenProperties = tweenProperties or ButtonUtils._getMouseOverTweenProperties(gui)

	if gui:IsA("GuiButton") then
		gui.AutoButtonColor = false
	end

	local maid, boolValue = ButtonUtils.GetMouseOverBoolValue(gui)
	local original = {}
	for property, _ in pairs(tweenProperties) do
		original[property] = gui[property]
	end

	local function update()
		for property, Value in pairs(boolValue.Value and tweenProperties or original) do
			gui[property] = Value
		end
	end
	update()
	maid:GiveTask(boolValue.Changed:Connect(update))

	self._maid[boolValue] = maid

	return boolValue
end

return MouseOverMixin
