function Icon.setLabel(c,N,U)N=N or""c:set("\105\099\111\110\084\101\120\116",N,U)return c end function Icon.setCornerRadius(v,N,U,c)local Z=v.instances.iconCorner.CornerRadius local q=UDim.new(N or Z.Scale,U or Z.Offset)v:set("\105\099\111\110\067\111\114\110\101\114\082\097\100\105\117\115",q,c)return v end function Icon.setImage(c,N,U)local v=tonumber(N)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"..N or N or""return c:set("\105\099\111\110\073\109\097\103\101",v,U)end function Icon.setOrder(c,N,U)local v=tonumber(N)or 1 return c:set("\111\114\100\101\114",v,U)end function Icon.setLeft(U,N)return U:set("\097\108\105\103\110\109\101\110\116","\108\101\102\116",N)end function Icon.setMid(U,N)return U:set("\097\108\105\103\110\109\101\110\116","\109\105\100",N)end function Icon.setRight(U,N)if not U.internalIcon then IconController.setupHealthbar()end return U:set("\097\108\105\103\110\109\101\110\116","\114\105\103\104\116",N)end function Icon.setImageYScale(c,N,U)local v=tonumber(N)or.63 return c:set("\105\099\111\110\073\109\097\103\101\089\083\099\097\108\101",v,U)end function Icon.setImageRatio(c,N,U)local v=tonumber(N)or 1 return c:set("\105\099\111\110\073\109\097\103\101\082\097\116\105\111",v,U)end function Icon.setLabelYScale(c,N,U)local v=tonumber(N)or.45 return c:set("\105\099\111\110\076\097\098\101\108\089\083\099\097\108\101",v,U)end function Icon.setBaseZIndex(c,N,U)local v=tonumber(N)or 1 return c:set("\098\097\115\101\090\073\110\100\101\120",v,U)end function Icon._updateBaseZIndex(U,N)local c=U.instances.iconContainer local v=tonumber(N)or c.ZIndex local Z=v-c.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 N,U in pairs(U.instances)do if U:IsA("\071\117\105\079\098\106\101\099\116")then U.ZIndex=U.ZIndex+Z end end return true end function Icon.setSize(v,N,U,c)if tonumber(N)then v.forcefullyAppliedXSize=true v:set("\102\111\114\099\101\100\073\099\111\110\083\105\122\101\088",tonumber(N),c)else v.forcefullyAppliedXSize=false v:set("\102\111\114\099\101\100\073\099\111\110\083\105\122\101\088",32,c)end if tonumber(U)then v.forcefullyAppliedYSize=true v:set("\102\111\114\099\101\100\073\099\111\110\083\105\122\101\089",tonumber(U),c)else v.forcefullyAppliedYSize=false v:set("\102\111\114\099\101\100\073\099\111\110\083\105\122\101\089",32,c)end local Z=tonumber(N)or 32 local q=tonumber(U)or U~="\095\078\073\076"and Z or 32 v:set("\105\099\111\110\083\105\122\101",UDim2.new(0,Z,0,q),c)return v end function Icon.setXSize(c,N,U)c:setSize(N,"\095\078\073\076",U)return c end function Icon.setYSize(c,N,U)c:setSize("\095\078\073\076",N,U)return c end function Icon._getContentText(U,N)U.instances.fakeIconLabel.Text=N local c=U.instances.fakeIconLabel.ContentText local v=typeof(U.instances.iconLabel)=="\073\110\115\116\097\110\099\101"and IconController.translator:Translate(U.instances.iconLabel,c)if typeof(v)~="\115\116\114\105\110\103"or v==""then v=c end U.instances.fakeIconLabel.Text=""return v end function Icon._updateIconSize(c,N,U)if c._destroyed then return end local v=12 local Z=8 local q={iconImage=c:get("\105\099\111\110\073\109\097\103\101",U)or"\095\078\073\076",iconText=c:get("\105\099\111\110\084\101\120\116",U)or"\095\078\073\076",iconFont=c:get("\105\099\111\110\070\111\110\116",U)or"\095\078\073\076",iconSize=c:get("\105\099\111\110\083\105\122\101",U)or"\095\078\073\076";forcedIconSizeX=c:get("\102\111\114\099\101\100\073\099\111\110\083\105\122\101\088",U)or"\095\078\073\076",iconImageYScale=c:get("\105\099\111\110\073\109\097\103\101\089\083\099\097\108\101",U)or"\095\078\073\076";iconImageRatio=c:get("\105\099\111\110\073\109\097\103\101\082\097\116\105\111",U)or"\095\078\073\076",iconLabelYScale=c:get("\105\099\111\110\076\097\098\101\108\089\083\099\097\108\101",U)or"\095\078\073\076"}for N,U in pairs(q)do if U=="\095\078\073\076"then return end end local b=c.instances.iconContainer if not b.Parent then return end local s=q.iconSize.X.Offset local H=q.iconSize.X.Scale local B=s+H*b.Parent.AbsoluteSize.X local g=q.forcedIconSizeX local S=H>0 and B or c.forcefullyAppliedXSize and g or 9999 local I=q.iconSize.Y.Offset local l=q.iconSize.Y.Scale local O=I+l*b.Parent.AbsoluteSize.Y local z=O*q.iconLabelYScale local K=c:_getContentText(q.iconText)local y=(textService:GetTextSize(K,z,q.iconFont,Vector2.new(10000,z))).X local f=(O*q.iconImageYScale)*q.iconImageRatio local Q=q.iconImage~=""local d=q.iconText~=""local C=.5 local x local k=z/2 if Q and not d then x=0 C=.45 c:set("\105\099\111\110\073\109\097\103\101\086\105\115\105\098\108\101",true,U)c: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),U)c:set("\105\099\111\110\073\109\097\103\101\080\111\115\105\116\105\111\110",UDim2.new(.5,0,.5,0),U)c:set("\105\099\111\110\073\109\097\103\101\083\105\122\101",UDim2.new(q.iconImageYScale*q.iconImageRatio,0,q.iconImageYScale,0),U)c:set("\105\099\111\110\076\097\098\101\108\086\105\115\105\098\108\101",false,U)elseif not Q and d then x=y+v*2 c:set("\105\099\111\110\076\097\098\101\108\086\105\115\105\098\108\101",true,U)c: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),U)c:set("\105\099\111\110\076\097\098\101\108\080\111\115\105\116\105\111\110",UDim2.new(0,v,.5,0),U)c:set("\105\099\111\110\076\097\098\101\108\083\105\122\101",UDim2.new(1,-v*2,q.iconLabelYScale,k),U)c: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,U)c:set("\105\099\111\110\073\109\097\103\101\086\105\115\105\098\108\101",false,U)elseif Q and d then local N=(v+f)+Z x=(N+y)+v c:set("\105\099\111\110\073\109\097\103\101\086\105\115\105\098\108\101",true,U)c: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),U)c:set("\105\099\111\110\073\109\097\103\101\080\111\115\105\116\105\111\110",UDim2.new(0,v,.5,0),U)c:set("\105\099\111\110\073\109\097\103\101\083\105\122\101",UDim2.new(0,f,q.iconImageYScale,0),U)c:set("\105\099\111\110\076\097\098\101\108\086\105\115\105\098\108\101",true,U)c: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),U)c:set("\105\099\111\110\076\097\098\101\108\080\111\115\105\116\105\111\110",UDim2.new(0,N,.5,0),U)c:set("\105\099\111\110\076\097\098\101\108\083\105\122\101",UDim2.new(1,-N-v,q.iconLabelYScale,k),U)c: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,U)end if x then if not c._updatingIconSize then c._updatingIconSize=true local N=H>0 and H or 0 local v=H>0 and 0 or math.clamp(x,g,S)c:set("\105\099\111\110\083\105\122\101",UDim2.new(N,v,q.iconSize.Y.Scale,q.iconSize.Y.Offset),U,"\095\105\103\110\111\114\101\080\114\101\118\105\111\117\115")local Z=c._parentIcon if Z then local N=UDim2.new(0,x,0,q.iconSize.Y.Offset)if#Z.dropdownIcons>0 then c:setAdditionalValue("\105\099\111\110\083\105\122\101","\098\101\102\111\114\101\068\114\111\112\100\111\119\110",N,U)Z:_updateDropdown()end if#Z.menuIcons>0 then c:setAdditionalValue("\105\099\111\110\083\105\122\101","\098\101\102\111\114\101\077\101\110\117",N,U)Z:_updateMenu()end end c._updatingIconSize=false end end c:set("\105\099\111\110\076\097\098\101\108\084\101\120\116\083\105\122\101",z,U)c:set("\110\111\116\105\099\101\070\114\097\109\101\080\111\115\105\116\105\111\110",UDim2.new(C,0,0,-2),U)c._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
		if object:IsA("GuiObject") then
			object.ZIndex = object.ZIndex + difference
		end
	end
	return true
end

function Icon:setSize(XOffset, YOffset, iconState)
	if tonumber(XOffset) then
		self.forcefullyAppliedXSize = true
		self:set("forcedIconSizeX", tonumber(XOffset), iconState)
	else
		self.forcefullyAppliedXSize = false
		self:set("forcedIconSizeX", 32, iconState)
	end
	if tonumber(YOffset) then
		self.forcefullyAppliedYSize = true
		self:set("forcedIconSizeY", tonumber(YOffset), iconState)
	else
		self.forcefullyAppliedYSize = false
		self:set("forcedIconSizeY", 32, iconState)
	end
	local newXOffset = tonumber(XOffset) or 32
	local newYOffset = tonumber(YOffset) or (YOffset ~= "_NIL" and newXOffset) or 32
	self:set("iconSize", UDim2.new(0, newXOffset, 0, newYOffset), iconState)
	return self
end

function Icon:setXSize(XOffset, iconState)
	self:setSize(XOffset, "_NIL", iconState)
	return self
end

function Icon:setYSize(YOffset, iconState)
	self:setSize("_NIL", YOffset, iconState)
	return self
end

function Icon:_getContentText(text)
	-- This converts richtext (e.g. "<b>Shop</b>") to normal text (e.g. "Shop")
	-- This also converts richtext/normaltext into its localized (translated) version
	-- This is important when calculating the size of the label/box for instance
	self.instances.fakeIconLabel.Text = text
	local textToTranslate = self.instances.fakeIconLabel.ContentText
	local translatedContentText = typeof(self.instances.iconLabel) == "Instance" and IconController.translator:Translate(self.instances.iconLabel, textToTranslate)
	if typeof(translatedContentText) ~= "string" or translatedContentText == "" then
		translatedContentText = textToTranslate
	end
	self.instances.fakeIconLabel.Text = ""
	return translatedContentText
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",
		forcedIconSizeX = self:get("forcedIconSizeX", 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.forcedIconSizeX--cellWidth
	local maxCellWidth = (cellSizeXScale > 0 and cellWidth) or (self.forcefullyAppliedXSize and minCellWidth) 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 iconContentText = self:_getContentText(values.iconText)
	local labelWidth = textService:GetTextSize(iconContentText, 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
		desiredCellWidth = 0
		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


