function Icon.setLabel(h,F,Q)F=F or""h:set("\105\099\111\110\084\101\120\116",F,Q)return h end function Icon.setCornerRadius(q,F,Q,h)local z=q.instances.iconCorner.CornerRadius local o=UDim.new(F or z.Scale,Q or z.Offset)q:set("\105\099\111\110\067\111\114\110\101\114\082\097\100\105\117\115",o,h)return q end function Icon.setImage(h,F,Q)local q=tonumber(F)and"\104\116\116\112\058\047\047\119\119\119\046\114\111\098\108\111\120\046\099\111\109\047\097\115\115\101\116\047\063\105\100\061"..F or F or""return h:set("\105\099\111\110\073\109\097\103\101",q,Q)end function Icon.setOrder(h,F,Q)local q=tonumber(F)or 1 return h:set("\111\114\100\101\114",q,Q)end function Icon.setLeft(Q,F)return Q:set("\097\108\105\103\110\109\101\110\116","\108\101\102\116",F)end function Icon.setMid(Q,F)return Q:set("\097\108\105\103\110\109\101\110\116","\109\105\100",F)end function Icon.setRight(Q,F)if not Q.internalIcon then IconController.setupHealthbar()end return Q:set("\097\108\105\103\110\109\101\110\116","\114\105\103\104\116",F)end function Icon.setImageYScale(h,F,Q)local q=tonumber(F)or.63 return h:set("\105\099\111\110\073\109\097\103\101\089\083\099\097\108\101",q,Q)end function Icon.setImageRatio(h,F,Q)local q=tonumber(F)or 1 return h:set("\105\099\111\110\073\109\097\103\101\082\097\116\105\111",q,Q)end function Icon.setLabelYScale(h,F,Q)local q=tonumber(F)or.45 return h:set("\105\099\111\110\076\097\098\101\108\089\083\099\097\108\101",q,Q)end function Icon.setBaseZIndex(h,F,Q)local q=tonumber(F)or 1 return h:set("\098\097\115\101\090\073\110\100\101\120",q,Q)end function Icon._updateBaseZIndex(Q,F)local h=Q.instances.iconContainer local q=tonumber(F)or h.ZIndex local z=q-h.ZIndex if z==0 then return"\084\104\101 \098\097\115\101\086\097\108\117\101 \105\115 \116\104\101 \115\097\109\101"end for F,Q in pairs(Q.instances)do Q.ZIndex=Q.ZIndex+z end return true end function Icon.setSize(q,F,Q,h)local z=tonumber(F)or 32 local o=tonumber(Q)or z q:set("\102\111\114\099\101\100\073\099\111\110\083\105\122\101",UDim2.new(0,z,0,o),h)q:set("\105\099\111\110\083\105\122\101",UDim2.new(0,z,0,o),h)return q end function Icon._updateIconSize(h,F,Q)if h._destroyed then return end local q=12 local z=8 local o={iconImage=h:get("\105\099\111\110\073\109\097\103\101",Q)or"\095\078\073\076",iconText=h:get("\105\099\111\110\084\101\120\116",Q)or"\095\078\073\076",iconFont=h:get("\105\099\111\110\070\111\110\116",Q)or"\095\078\073\076",iconSize=h:get("\105\099\111\110\083\105\122\101",Q)or"\095\078\073\076";forcedIconSize=h:get("\102\111\114\099\101\100\073\099\111\110\083\105\122\101",Q)or"\095\078\073\076";iconImageYScale=h:get("\105\099\111\110\073\109\097\103\101\089\083\099\097\108\101",Q)or"\095\078\073\076";iconImageRatio=h:get("\105\099\111\110\073\109\097\103\101\082\097\116\105\111",Q)or"\095\078\073\076";iconLabelYScale=h:get("\105\099\111\110\076\097\098\101\108\089\083\099\097\108\101",Q)or"\095\078\073\076"}for F,Q in pairs(o)do if Q=="\095\078\073\076"then return end end local y=h.instances.iconContainer if not y.Parent then return end local E=o.iconSize.X.Offset local Z=o.iconSize.X.Scale local c=E+Z*y.Parent.AbsoluteSize.X local d=o.forcedIconSize.X.Offset local w=Z>0 and c or 9999 local H=o.iconSize.Y.Offset local u=o.iconSize.Y.Scale local N=H+u*y.Parent.AbsoluteSize.Y local G=N*o.iconLabelYScale local t=(textService:GetTextSize(o.iconText,G,o.iconFont,Vector2.new(10000,G))).X local b=(N*o.iconImageYScale)*o.iconImageRatio local f=o.iconImage~=""local B=o.iconText~=""local O=.5 local X local L=G/2 if f and not B then O=.45 h:set("\105\099\111\110\073\109\097\103\101\086\105\115\105\098\108\101",true,Q)h:set("\105\099\111\110\073\109\097\103\101\065\110\099\104\111\114\080\111\105\110\116",Vector2.new(.5,.5),Q)h:set("\105\099\111\110\073\109\097\103\101\080\111\115\105\116\105\111\110",UDim2.new(.5,0,.5,0),Q)h:set("\105\099\111\110\073\109\097\103\101\083\105\122\101",UDim2.new(o.iconImageYScale*o.iconImageRatio,0,o.iconImageYScale,0),Q)h:set("\105\099\111\110\076\097\098\101\108\086\105\115\105\098\108\101",false,Q)elseif not f and B then X=t+q*2 h:set("\105\099\111\110\076\097\098\101\108\086\105\115\105\098\108\101",true,Q)h:set("\105\099\111\110\076\097\098\101\108\065\110\099\104\111\114\080\111\105\110\116",Vector2.new(0,.5),Q)h:set("\105\099\111\110\076\097\098\101\108\080\111\115\105\116\105\111\110",UDim2.new(0,q,.5,0),Q)h:set("\105\099\111\110\076\097\098\101\108\083\105\122\101",UDim2.new(1,-q*2,o.iconLabelYScale,L),Q)h:set("\105\099\111\110\076\097\098\101\108\084\101\120\116\088\065\108\105\103\110\109\101\110\116",Enum.TextXAlignment.Center,Q)h:set("\105\099\111\110\073\109\097\103\101\086\105\115\105\098\108\101",false,Q)elseif f and B then local F=(q+b)+z X=(F+t)+q h:set("\105\099\111\110\073\109\097\103\101\086\105\115\105\098\108\101",true,Q)h:set("\105\099\111\110\073\109\097\103\101\065\110\099\104\111\114\080\111\105\110\116",Vector2.new(0,.5),Q)h:set("\105\099\111\110\073\109\097\103\101\080\111\115\105\116\105\111\110",UDim2.new(0,q,.5,0),Q)h:set("\105\099\111\110\073\109\097\103\101\083\105\122\101",UDim2.new(0,b,o.iconImageYScale,0),Q)h:set("\105\099\111\110\076\097\098\101\108\086\105\115\105\098\108\101",true,Q)h:set("\105\099\111\110\076\097\098\101\108\065\110\099\104\111\114\080\111\105\110\116",Vector2.new(0,.5),Q)h:set("\105\099\111\110\076\097\098\101\108\080\111\115\105\116\105\111\110",UDim2.new(0,F,.5,0),Q)h:set("\105\099\111\110\076\097\098\101\108\083\105\122\101",UDim2.new(1,-F-q,o.iconLabelYScale,L),Q)h:set("\105\099\111\110\076\097\098\101\108\084\101\120\116\088\065\108\105\103\110\109\101\110\116",Enum.TextXAlignment.Left,Q)end if X then if not h._updatingIconSize then h._updatingIconSize=true local F=Z>0 and Z or 0 local q=Z>0 and 0 or math.clamp(X,d,w)h:set("\105\099\111\110\083\105\122\101",UDim2.new(F,q,o.iconSize.Y.Scale,o.iconSize.Y.Offset),Q,"\095\105\103\110\111\114\101\080\114\101\118\105\111\117\115")local z=h._parentIcon if z then local F=UDim2.new(0,X,0,o.iconSize.Y.Offset)if#z.dropdownIcons>0 then h:setAdditionalValue("\105\099\111\110\083\105\122\101","\098\101\102\111\114\101\068\114\111\112\100\111\119\110",F,Q)z:_updateDropdown()end if#z.menuIcons>0 then h:setAdditionalValue("\105\099\111\110\083\105\122\101","\098\101\102\111\114\101\077\101\110\117",F,Q)z:_updateMenu()end end h._updatingIconSize=false end end h:set("\105\099\111\110\076\097\098\101\108\084\101\120\116\083\105\122\101",G,Q)h:set("\110\111\116\105\099\101\070\114\097\109\101\080\111\115\105\116\105\111\110",UDim2.new(O,0,0,-2),Q)h._updatingIconSize=false end

function Icon:setLabel(text, iconState)
	text = text or ""
	self:set("iconText", text, iconState)
	return self
end

function Icon:setCornerRadius(scale, offset, iconState)
	local oldCornerRadius = self.instances.iconCorner.CornerRadius
	local newCornerRadius = UDim.new(scale or oldCornerRadius.Scale, offset or oldCornerRadius.Offset)
	self:set("iconCornerRadius", newCornerRadius, iconState)
	return self
end

function Icon:setImage(imageId, iconState)
	local textureId = (tonumber(imageId) and "http://www.roblox.com/asset/?id="..imageId) or imageId or ""
	return self:set("iconImage", textureId, iconState)
end

function Icon:setOrder(order, iconState)
	local newOrder = tonumber(order) or 1
	return self:set("order", newOrder, iconState)
end

function Icon:setLeft(iconState)
	return self:set("alignment", "left", iconState)
end

function Icon:setMid(iconState)
	return self:set("alignment", "mid", iconState)
end

function Icon:setRight(iconState)
	if not self.internalIcon then
		IconController.setupHealthbar()
	end
	return self:set("alignment", "right", iconState)
end

function Icon:setImageYScale(YScale, iconState)
	local newYScale = tonumber(YScale) or 0.63
	return self:set("iconImageYScale", newYScale, iconState)
end

function Icon:setImageRatio(ratio, iconState)
	local newRatio = tonumber(ratio) or 1
	return self:set("iconImageRatio", newRatio, iconState)
end

function Icon:setLabelYScale(YScale, iconState)
	local newYScale = tonumber(YScale) or 0.45
	return self:set("iconLabelYScale", newYScale, iconState)
end
	
function Icon:setBaseZIndex(ZIndex, iconState)
	local newBaseZIndex = tonumber(ZIndex) or 1
	return self:set("baseZIndex", newBaseZIndex, iconState)
end

function Icon:_updateBaseZIndex(baseValue)
	local container = self.instances.iconContainer
	local newBaseValue = tonumber(baseValue) or container.ZIndex
	local difference = newBaseValue - container.ZIndex
	if difference == 0 then return "The baseValue is the same" end
	for _, object in pairs(self.instances) do
		object.ZIndex = object.ZIndex + difference
	end
	return true
end

function Icon:setSize(XOffset, YOffset, iconState)
	local newXOffset = tonumber(XOffset) or 32
	local newYOffset = tonumber(YOffset) or newXOffset
	self:set("forcedIconSize", UDim2.new(0, newXOffset, 0, newYOffset), iconState)
	self:set("iconSize", UDim2.new(0, newXOffset, 0, newYOffset), iconState)
	return self
end

function Icon:_updateIconSize(_, iconState)
	if self._destroyed then return end
	-- This is responsible for handling the appearance and size of the icons label and image, in additon to its own size
	local X_MARGIN = 12
	local X_GAP = 8

	local values = {
		iconImage = self:get("iconImage", iconState) or "_NIL",
		iconText = self:get("iconText", iconState) or "_NIL",
		iconFont = self:get("iconFont", iconState) or "_NIL",
		iconSize = self:get("iconSize", iconState) or "_NIL",
		forcedIconSize = self:get("forcedIconSize", iconState) or "_NIL",
		iconImageYScale = self:get("iconImageYScale", iconState) or "_NIL",
		iconImageRatio = self:get("iconImageRatio", iconState) or "_NIL",
		iconLabelYScale = self:get("iconLabelYScale", iconState) or "_NIL",
	}
	for k,v in pairs(values) do
		if v == "_NIL" then
			return
		end
	end

	local iconContainer = self.instances.iconContainer
	if not iconContainer.Parent then return end

	-- We calculate the cells dimensions as apposed to reading because there's a possibility the cells dimensions were changed at the exact time and have not yet updated
	-- this essentially saves us from waiting a heartbeat which causes additonal complications
	local cellSizeXOffset = values.iconSize.X.Offset
	local cellSizeXScale = values.iconSize.X.Scale
	local cellWidth = cellSizeXOffset + (cellSizeXScale * iconContainer.Parent.AbsoluteSize.X)
	local minCellWidth = values.forcedIconSize.X.Offset--cellWidth
	local maxCellWidth = (cellSizeXScale > 0 and cellWidth) or 9999
	local cellSizeYOffset = values.iconSize.Y.Offset
	local cellSizeYScale = values.iconSize.Y.Scale
	local cellHeight = cellSizeYOffset + (cellSizeYScale * iconContainer.Parent.AbsoluteSize.Y)
	local labelHeight = cellHeight * values.iconLabelYScale
	local labelWidth = textService:GetTextSize(values.iconText, labelHeight, values.iconFont, Vector2.new(10000, labelHeight)).X
	local imageWidth = cellHeight * values.iconImageYScale * values.iconImageRatio
	
	local usingImage = values.iconImage ~= ""
	local usingText = values.iconText ~= ""
	local notifPosYScale = 0.5
	local desiredCellWidth
	local preventClippingOffset = labelHeight/2
	
	if usingImage and not usingText then
		notifPosYScale = 0.45
		self:set("iconImageVisible", true, iconState)
		self:set("iconImageAnchorPoint", Vector2.new(0.5, 0.5), iconState)
		self:set("iconImagePosition", UDim2.new(0.5, 0, 0.5, 0), iconState)
		self:set("iconImageSize", UDim2.new(values.iconImageYScale*values.iconImageRatio, 0, values.iconImageYScale, 0), iconState)
		self:set("iconLabelVisible", false, iconState)

	elseif not usingImage and usingText then
		desiredCellWidth = labelWidth+(X_MARGIN*2)
		self:set("iconLabelVisible", true, iconState)
		self:set("iconLabelAnchorPoint", Vector2.new(0, 0.5), iconState)
		self:set("iconLabelPosition", UDim2.new(0, X_MARGIN, 0.5, 0), iconState)
		self:set("iconLabelSize", UDim2.new(1, -X_MARGIN*2, values.iconLabelYScale, preventClippingOffset), iconState)
		self:set("iconLabelTextXAlignment", Enum.TextXAlignment.Center, iconState)
		self:set("iconImageVisible", false, iconState)

	elseif usingImage and usingText then
		local labelGap = X_MARGIN + imageWidth + X_GAP
		desiredCellWidth = labelGap + labelWidth + X_MARGIN
		self:set("iconImageVisible", true, iconState)
		self:set("iconImageAnchorPoint", Vector2.new(0, 0.5), iconState)
		self:set("iconImagePosition", UDim2.new(0, X_MARGIN, 0.5, 0), iconState)
		self:set("iconImageSize", UDim2.new(0, imageWidth, values.iconImageYScale, 0), iconState)
		----
		self:set("iconLabelVisible", true, iconState)
		self:set("iconLabelAnchorPoint", Vector2.new(0, 0.5), iconState)
		self:set("iconLabelPosition", UDim2.new(0, labelGap, 0.5, 0), iconState)
		self:set("iconLabelSize", UDim2.new(1, -labelGap-X_MARGIN, values.iconLabelYScale, preventClippingOffset), iconState)
		self:set("iconLabelTextXAlignment", Enum.TextXAlignment.Left, iconState)
	end
	if desiredCellWidth then
		if not self._updatingIconSize then
			self._updatingIconSize = true
			local widthScale = (cellSizeXScale > 0 and cellSizeXScale) or 0
			local widthOffset = (cellSizeXScale > 0 and 0) or math.clamp(desiredCellWidth, minCellWidth, maxCellWidth)
			self:set("iconSize", UDim2.new(widthScale, widthOffset, values.iconSize.Y.Scale, values.iconSize.Y.Offset), iconState, "_ignorePrevious")

			-- This ensures that if an icon is within a dropdown or menu, its container adapts accordingly with this new iconSize value
			local parentIcon = self._parentIcon
			if parentIcon then
				local originalIconSize = UDim2.new(0, desiredCellWidth, 0, values.iconSize.Y.Offset)
				if #parentIcon.dropdownIcons > 0 then
					self:setAdditionalValue("iconSize", "beforeDropdown", originalIconSize, iconState)
					parentIcon:_updateDropdown()
				end
				if #parentIcon.menuIcons > 0 then
					self:setAdditionalValue("iconSize", "beforeMenu", originalIconSize, iconState)
					parentIcon:_updateMenu()
				end
			end

			self._updatingIconSize = false
		end
	end
	self:set("iconLabelTextSize", labelHeight, iconState)
	self:set("noticeFramePosition", UDim2.new(notifPosYScale, 0, 0, -2), iconState)

	self._updatingIconSize = false
end


