local Q=game:GetService("\085\115\101\114\073\110\112\117\116\083\101\114\118\105\099\101")local c=game:GetService("\071\117\105\083\101\114\118\105\099\101")local k={}k.__index=k function k.Connect(Q,c,s,i)local K={}setmetatable(K,k)K.Connections={}K.Active=false if Q and(c or s)then if i then table.insert(K.Connections,Q.SelectionGained:Connect(function()K.Active=true if c then c()end end))table.insert(K.Connections,Q.SelectionLost:Connect(function()K.Active=true if s then s()end end))end table.insert(K.Connections,Q.InputBegan:Connect(function(Q)if Q.UserInputType==Enum.UserInputType.MouseMovement then K.Active=true if c then c()end end end))table.insert(K.Connections,Q.InputEnded:Connect(function(Q)if Q.UserInputType==Enum.UserInputType.MouseMovement then K.Active=false if s then s()end end end))end return K end function k.Disconnect(Q)if Q and Q.Connections then for c=1,#Q.Connections,1 do local k=Q.Connections[c]if k then k:Disconnect()end end end Q=nil end return k
--[[
	Useful for hovering over ui elements
--]]

local UserInputService = game:GetService("UserInputService")
local GuiService = game:GetService("GuiService")

local Hover = {}
Hover.__index = Hover

-- pass the element, and two functions (1=enter, 2=leave)
function Hover.Connect(element, enter, leave, call_leave_on_selection_lost)
	local self = {}
	setmetatable(self, Hover)
	self.Connections = {}
	self.Active = false
	if element and (enter or leave) then -- support both, or just one function (maybe we just want a sound to play on leave, etc)
		if call_leave_on_selection_lost then
			table.insert(
				self.Connections,
				element.SelectionGained:Connect(function()
					self.Active = true
					if enter then
						enter()
					end
				end)
			)
			table.insert(
				self.Connections,
				element.SelectionLost:Connect(function()
					self.Active = true
					if leave then
						leave()
					end
				end)
			)
		end
		table.insert(
			self.Connections,
			element.InputBegan:Connect(function(input)
				if input.UserInputType == Enum.UserInputType.MouseMovement then
					self.Active = true
					if enter then
						enter()
					end
				end
			end)
		)
		table.insert(
			self.Connections,
			element.InputEnded:Connect(function(input)
				if input.UserInputType == Enum.UserInputType.MouseMovement then
					self.Active = false
					if leave then
						leave()
					end
				end
			end)
		)
	end

	return self
end

-- disconnects the events.
function Hover:Disconnect()
	if self and self.Connections then
		for i = 1, #self.Connections do
			local connection = self.Connections[i]
			if connection then
				connection:Disconnect()
			end
		end
	end
	self = nil
end

return Hover
