function Icon.bindEvent(t,V,c)local s=t[V]assert(s and(typeof(s)=="\116\097\098\108\101"and s.Connect),"\097\114\103\117\109\101\110\116\091\049\093 \109\117\115\116 \098\101 \097 \118\097\108\105\100 \116\111\112\098\097\114\112\108\117\115 \105\099\111\110 \101\118\101\110\116 \110\097\109\101\033")assert(typeof(c)=="\102\117\110\099\116\105\111\110","\097\114\103\117\109\101\110\116\091\050\093 \109\117\115\116 \098\101 \097 \102\117\110\099\116\105\111\110\033")t._bindedEvents[V]=s:Connect(function(...)c(t,...)end)return t end function Icon.unbindEvent(c,V)local t=c._bindedEvents[V]if t then t:Disconnect()c._bindedEvents[V]=nil end return c end function Icon.bindToggleKey(c,V)assert(typeof(V)=="\069\110\117\109\073\116\101\109","\097\114\103\117\109\101\110\116\091\049\093 \109\117\115\116 \098\101 \097 \075\101\121\067\111\100\101 \069\110\117\109\073\116\101\109\033")c._bindedToggleKeys[V]=true return c end function Icon.unbindToggleKey(c,V)assert(typeof(V)=="\069\110\117\109\073\116\101\109","\097\114\103\117\109\101\110\116\091\049\093 \109\117\115\116 \098\101 \097 \075\101\121\067\111\100\101 \069\110\117\109\073\116\101\109\033")c._bindedToggleKeys[V]=nil return c end function Icon.lock(V)V.locked=true return V end function Icon.unlock(V)V.locked=false return V end function Icon.setTopPadding(t,V,c)local s=V or 4 local h=c or 0 t.topPadding=UDim.new(h,s)t.updated:Fire()return t end function Icon.bindToggleItem(c,V)if not V:IsA("\071\117\105\079\098\106\101\099\116")and not V:IsA("\076\097\121\101\114\067\111\108\108\101\099\116\111\114")then error("\084\111\103\103\108\101 \105\116\101\109 \109\117\115\116 \098\101 \097 \071\117\105\079\098\106\101\099\116 \111\114 \076\097\121\101\114\067\111\108\108\101\099\116\111\114\033")end c.toggleItems[V]=true return c end function Icon.unbindToggleItem(c,V)c.toggleItems[V]=nil return c end function Icon._setToggleItemsVisible(t,V,c)for t,s in pairs(t.toggleItems)do if not c or c.toggleItems[t]==nil then local c="\086\105\115\105\098\108\101"if t:IsA("\076\097\121\101\114\067\111\108\108\101\099\116\111\114")then c="\069\110\097\098\108\101\100"end t[c]=V end end end function Icon.give(c,V)local t=V if typeof(V)=="\102\117\110\099\116\105\111\110"then local s=V(c)if typeof(V)~="\102\117\110\099\116\105\111\110"then t=s end end c._maid:give(t)return c end
-- FEATURE METHODS
function Icon:bindEvent(iconEventName, eventFunction)
	local event = self[iconEventName]
	assert(
		event and typeof(event) == "table" and event.Connect,
		"argument[1] must be a valid topbarplus icon event name!"
	)
	assert(typeof(eventFunction) == "function", "argument[2] must be a function!")
	self._bindedEvents[iconEventName] = event:Connect(function(...)
		eventFunction(self, ...)
	end)
	return self
end

function Icon:unbindEvent(iconEventName)
	local eventConnection = self._bindedEvents[iconEventName]
	if eventConnection then
		eventConnection:Disconnect()
		self._bindedEvents[iconEventName] = nil
	end
	return self
end

function Icon:bindToggleKey(keyCodeEnum)
	assert(typeof(keyCodeEnum) == "EnumItem", "argument[1] must be a KeyCode EnumItem!")
	self._bindedToggleKeys[keyCodeEnum] = true
	return self
end

function Icon:unbindToggleKey(keyCodeEnum)
	assert(typeof(keyCodeEnum) == "EnumItem", "argument[1] must be a KeyCode EnumItem!")
	self._bindedToggleKeys[keyCodeEnum] = nil
	return self
end

function Icon:lock()
	self.locked = true
	return self
end

function Icon:unlock()
	self.locked = false
	return self
end

function Icon:setTopPadding(offset, scale)
	local newOffset = offset or 4
	local newScale = scale or 0
	self.topPadding = UDim.new(newScale, newOffset)
	self.updated:Fire()
	return self
end

function Icon:bindToggleItem(guiObjectOrLayerCollector)
	if not guiObjectOrLayerCollector:IsA("GuiObject") and not guiObjectOrLayerCollector:IsA("LayerCollector") then
		error("Toggle item must be a GuiObject or LayerCollector!")
	end
	self.toggleItems[guiObjectOrLayerCollector] = true
	return self
end

function Icon:unbindToggleItem(guiObjectOrLayerCollector)
	self.toggleItems[guiObjectOrLayerCollector] = nil
	return self
end

function Icon:_setToggleItemsVisible(bool, byIcon)
	for toggleItem, _ in pairs(self.toggleItems) do
		if not byIcon or byIcon.toggleItems[toggleItem] == nil then
			local property = "Visible"
			if toggleItem:IsA("LayerCollector") then
				property = "Enabled"
			end
			toggleItem[property] = bool
		end
	end
end

function Icon:give(userdata)
	local valueToGive = userdata
	if typeof(userdata) == "function" then
		local returnValue = userdata(self)
		if typeof(userdata) ~= "function" then
			valueToGive = returnValue
		end
	end
	self._maid:give(valueToGive)
	return self
end
