function Icon.bindEvent(c,s,I)local M=c[s]assert(M and(typeof(M)=="\116\097\098\108\101"and M.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(I)=="\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")c._bindedEvents[s]=M:Connect(function(...)I(c,...)end)return c end function Icon.unbindEvent(I,s)local c=I._bindedEvents[s]if c then c:Disconnect()I._bindedEvents[s]=nil end return I end function Icon.bindToggleKey(I,s)assert(typeof(s)=="\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")I._bindedToggleKeys[s]=true return I end function Icon.unbindToggleKey(I,s)assert(typeof(s)=="\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")I._bindedToggleKeys[s]=nil return I end function Icon.lock(s)s.locked=true return s end function Icon.unlock(s)s.locked=false return s end function Icon.setTopPadding(c,s,I)local M=s or 4 local e=I or 0 c.topPadding=UDim.new(e,M)c.updated:Fire()return c end function Icon.bindToggleItem(I,s)if not s:IsA("\071\117\105\079\098\106\101\099\116")and not s: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 I.toggleItems[s]=true return I end function Icon.unbindToggleItem(I,s)I.toggleItems[s]=nil return I end function Icon._setToggleItemsVisible(c,s,I)for c,M in pairs(c.toggleItems)do if not I or I.toggleItems[c]==nil then local I="\086\105\115\105\098\108\101"if c:IsA("\076\097\121\101\114\067\111\108\108\101\099\116\111\114")then I="\069\110\097\098\108\101\100"end c[I]=s end end end

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
