function Icon.join(M,U,f,j)if M._parentIcon then M:leave()end local n=f and f:lower()or"\100\114\111\112\100\111\119\110"local o="\098\101\102\111\114\101"..((f:sub(1,1)):upper()..f:sub(2))local H=U.instances[f.."\070\114\097\109\101"]M.presentOnTopbar=false M.joinedFeatureName=f M._parentIcon=U M.instances.iconContainer.Parent=H for f,j in pairs(M.notices)do U:notify(j.clearNoticeEvent,f)end if f=="\100\114\111\112\100\111\119\110"then local f=U:get("\100\114\111\112\100\111\119\110\083\113\117\097\114\101\067\111\114\110\101\114\115")M:set("\105\099\111\110\083\105\122\101",UDim2.new(1,0,0,(M:get("\105\099\111\110\083\105\122\101","\100\101\115\101\108\101\099\116\101\100")).Y.Offset),"\100\101\115\101\108\101\099\116\101\100",o)M:set("\105\099\111\110\083\105\122\101",UDim2.new(1,0,0,(M:get("\105\099\111\110\083\105\122\101","\115\101\108\101\099\116\101\100")).Y.Offset),"\115\101\108\101\099\116\101\100",o)if f then M:set("\105\099\111\110\067\111\114\110\101\114\082\097\100\105\117\115",UDim.new(0,0),"\100\101\115\101\108\101\099\116\101\100",o)M:set("\105\099\111\110\067\111\114\110\101\114\082\097\100\105\117\115",UDim.new(0,0),"\115\101\108\101\099\116\101\100",o)end M:set("\099\097\112\116\105\111\110\066\108\111\099\107\101\114\084\114\097\110\115\112\097\114\101\110\099\121",.4,nil,o)end local y=U[n.."\073\099\111\110\115"]table.insert(y,M)if not j then if f=="\100\114\111\112\100\111\119\110"then U:_updateDropdown()elseif f=="\109\101\110\117"then U:_updateMenu()end end U.deselectWhenOtherIconSelected=false IconController:_updateSelectionGroup()M:_decideToCallSignal("\100\114\111\112\100\111\119\110")M:_decideToCallSignal("\109\101\110\117")return M end function Icon.leave(U)if U._destroyed or U.instances.iconContainer.Parent==nil then return end local f={"\105\099\111\110\083\105\122\101";"\099\097\112\116\105\111\110\066\108\111\099\107\101\114\084\114\097\110\115\112\097\114\101\110\099\121";"\105\099\111\110\067\111\114\110\101\114\082\097\100\105\117\115"}local j=U._parentIcon U.instances.iconContainer.Parent=topbarContainer U.presentOnTopbar=true U.joinedFeatureName=nil local function M(M,n,o)for H,y in pairs(M)do if y==U then for f,j in pairs(f)do local M={"\100\101\115\101\108\101\099\116\101\100";"\115\101\108\101\099\116\101\100"}for f,M in pairs(M)do local o,H=U:get(j,M,n)if H then U:set(j,H,M)end end end table.remove(M,H)o(j)if#M==0 then U._parentIcon.deselectWhenOtherIconSelected=true end break end end end M(j.dropdownIcons,"\098\101\102\111\114\101\068\114\111\112\100\111\119\110",j._updateDropdown)M(j.menuIcons,"\098\101\102\111\114\101\077\101\110\117",j._updateMenu)for U,f in pairs(U.notices)do local M=j.notices[U]if M then M.completeSignal:Fire()end end U._parentIcon=nil IconController:_updateSelectionGroup()U:_decideToCallSignal("\100\114\111\112\100\111\119\110")U:_decideToCallSignal("\109\101\110\117")return U end function Icon._decideToCallSignal(f,U)local j=f[U.."\079\112\101\110"]local M="\095\112\114\101\118\105\111\117\115"..((string.sub(U,1,1)):upper()..(U:sub(2).."\079\112\101\110"))local n=f[M]local o=#f[U.."\073\099\111\110\115"]if j and(o>0 and n==false)then f[M]=true f[U.."\079\112\101\110\101\100"]:Fire()elseif(not j or o==0)and n==true then f[M]=false f[U.."\067\108\111\115\101\100"]:Fire()end end function Icon._ignoreClipping(f,U)local j=f:get(U.."\073\103\110\111\114\101\067\108\105\112\112\105\110\103")if f._parentIcon then local M=f["\095"..(U.."\067\108\105\112\112\105\110\103\077\097\105\100")]local n=f.instances[U.."\067\111\110\116\097\105\110\101\114"]M:clean()if j then local U=Instance.new("\070\114\097\109\101")U.Name=n.Name.."\070\097\107\101\070\114\097\109\101"U.ClipsDescendants=true U.BackgroundTransparency=1 U.Size=n.Size U.Position=n.Position U.Parent=activeItems for f,j in pairs(n:GetChildren())do j.Parent=U end local function f()local f=n.AbsoluteSize U.Size=UDim2.new(0,f.X,0,f.Y)end M:give((n:GetPropertyChangedSignal("\065\098\115\111\108\117\116\101\083\105\122\101")):Connect(function()f()end))f()local function j()local f=n.absolutePosition U.Position=UDim2.new(0,f.X,0,f.Y+36)end M:give((n:GetPropertyChangedSignal("\065\098\115\111\108\117\116\101\080\111\115\105\116\105\111\110")):Connect(function()j()end))j()M:give(function()for U,f in pairs(U:GetChildren())do f.Parent=n end U.Name="\068\101\115\116\114\111\121\105\110\103\046\046\046"U:Destroy()end)end end f._ignoreClippingChanged:Fire(U,j)end

function Icon:join(parentIcon, featureName, dontUpdate)
	if self._parentIcon then
		self:leave()
	end
	local newFeatureName = (featureName and featureName:lower()) or "dropdown"
	local beforeName = "before"..featureName:sub(1,1):upper()..featureName:sub(2)
	local parentFrame = parentIcon.instances[featureName.."Frame"]
	self.presentOnTopbar = false
	self.joinedFeatureName = featureName
	self._parentIcon = parentIcon
	self.instances.iconContainer.Parent = parentFrame
	for noticeId, noticeDetail in pairs(self.notices) do
		parentIcon:notify(noticeDetail.clearNoticeEvent, noticeId)
		--parentIcon:notify(noticeDetail.completeSignal, noticeId)
	end
	
	if featureName == "dropdown" then
		local squareCorners = parentIcon:get("dropdownSquareCorners")
		self:set("iconSize", UDim2.new(1, 0, 0, self:get("iconSize", "deselected").Y.Offset), "deselected", beforeName)
		self:set("iconSize", UDim2.new(1, 0, 0, self:get("iconSize", "selected").Y.Offset), "selected", beforeName)
		if squareCorners then
			self:set("iconCornerRadius", UDim.new(0, 0), "deselected", beforeName)
			self:set("iconCornerRadius", UDim.new(0, 0), "selected", beforeName)
		end
		self:set("captionBlockerTransparency", 0.4, nil, beforeName)
	end
	local array = parentIcon[newFeatureName.."Icons"]
	table.insert(array, self)
	if not dontUpdate then
		if featureName == "dropdown" then
			parentIcon:_updateDropdown()
		elseif featureName == "menu" then
			parentIcon:_updateMenu()
		end
	end
	parentIcon.deselectWhenOtherIconSelected = false
	--
	IconController:_updateSelectionGroup()
	self:_decideToCallSignal("dropdown")
	self:_decideToCallSignal("menu")
	--
	return self
end

function Icon:leave()
	if self._destroyed or self.instances.iconContainer.Parent == nil then
		return
	end
	local settingsToReset = {"iconSize", "captionBlockerTransparency", "iconCornerRadius"}
	local parentIcon = self._parentIcon
	self.instances.iconContainer.Parent = topbarContainer
	self.presentOnTopbar = true
	self.joinedFeatureName = nil
	local function scanFeature(t, prevReference, updateMethod)
		for i, otherIcon in pairs(t) do
			if otherIcon == self then
				for _, settingName in pairs(settingsToReset) do
					local states = {"deselected", "selected"}
					for _, toggleState in pairs(states) do
						local currentSetting, previousSetting = self:get(settingName, toggleState, prevReference)
						if previousSetting then
							self:set(settingName, previousSetting, toggleState)
						end
					end
				end
				table.remove(t, i)
				updateMethod(parentIcon)
				if #t == 0 then
					self._parentIcon.deselectWhenOtherIconSelected = true
				end
				break
			end
		end
	end
	scanFeature(parentIcon.dropdownIcons, "beforeDropdown", parentIcon._updateDropdown)
	scanFeature(parentIcon.menuIcons, "beforeMenu", parentIcon._updateMenu)
	--
	for noticeId, noticeDetail in pairs(self.notices) do
		local parentIconNoticeDetail = parentIcon.notices[noticeId]
		if parentIconNoticeDetail then
			parentIconNoticeDetail.completeSignal:Fire()
		end
	end
	--
	self._parentIcon = nil
	--
	IconController:_updateSelectionGroup()
	self:_decideToCallSignal("dropdown")
	self:_decideToCallSignal("menu")
	--
	return self
end

function Icon:_decideToCallSignal(featureName)
	local isOpen = self[featureName.."Open"]
	local previousIsOpenName = "_previous"..string.sub(featureName, 1, 1):upper()..featureName:sub(2).."Open"
	local previousIsOpen = self[previousIsOpenName]
	local totalIcons = #self[featureName.."Icons"]
	if isOpen and totalIcons > 0 and previousIsOpen == false then
		self[previousIsOpenName] = true
		self[featureName.."Opened"]:Fire()
	elseif (not isOpen or totalIcons == 0) and previousIsOpen == true then
		self[previousIsOpenName] = false
		self[featureName.."Closed"]:Fire()
	end
end

function Icon:_ignoreClipping(featureName)
	local ignoreClipping = self:get(featureName.."IgnoreClipping")
	if self._parentIcon then
		local maid = self["_"..featureName.."ClippingMaid"]
		local frame = self.instances[featureName.."Container"]
		maid:clean()
		if ignoreClipping then
			local fakeFrame = Instance.new("Frame")
			fakeFrame.Name = frame.Name.."FakeFrame"
			fakeFrame.ClipsDescendants = true
			fakeFrame.BackgroundTransparency = 1
			fakeFrame.Size = frame.Size
			fakeFrame.Position = frame.Position
			fakeFrame.Parent = activeItems
			--
			for a,b in pairs(frame:GetChildren()) do
				b.Parent = fakeFrame
			end
			--
			local function updateSize()
				local absoluteSize = frame.AbsoluteSize
				fakeFrame.Size = UDim2.new(0, absoluteSize.X, 0, absoluteSize.Y)
			end
			maid:give(frame:GetPropertyChangedSignal("AbsoluteSize"):Connect(function()
				updateSize()
			end))
			updateSize()
			local function updatePos()
				local absolutePosition = frame.absolutePosition
				fakeFrame.Position = UDim2.new(0, absolutePosition.X, 0, absolutePosition.Y+36)
			end
			maid:give(frame:GetPropertyChangedSignal("AbsolutePosition"):Connect(function()
				updatePos()
			end))
			updatePos()
			maid:give(function()
				for a,b in pairs(fakeFrame:GetChildren()) do
					b.Parent = frame
				end
				fakeFrame.Name = "Destroying..."
				fakeFrame:Destroy()
			end)
		end
	end
	self._ignoreClippingChanged:Fire(featureName, ignoreClipping)
end
