function Icon.setLabel(s,D,f)D=D or""s:set("\105\099\111\110\084\101\120\116",D,f)return s end function Icon.setCornerRadius(T,D,f,s)local l=T.instances.iconCorner.CornerRadius local B=UDim.new(D or l.Scale,f or l.Offset)T:set("\105\099\111\110\067\111\114\110\101\114\082\097\100\105\117\115",B,s)return T end function Icon.setImage(s,D,f)local T=tonumber(D)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"..D or D or""return s:set("\105\099\111\110\073\109\097\103\101",T,f)end function Icon.setOrder(s,D,f)local T=tonumber(D)or 1 return s:set("\111\114\100\101\114",T,f)end function Icon.setLeft(f,D)return f:set("\097\108\105\103\110\109\101\110\116","\108\101\102\116",D)end function Icon.setMid(f,D)return f:set("\097\108\105\103\110\109\101\110\116","\109\105\100",D)end function Icon.setRight(f,D)return f:set("\097\108\105\103\110\109\101\110\116","\114\105\103\104\116",D)end function Icon.setImageYScale(s,D,f)local T=tonumber(D)or.63 return s:set("\105\099\111\110\073\109\097\103\101\089\083\099\097\108\101",T,f)end function Icon.setImageRatio(s,D,f)local T=tonumber(D)or 1 return s:set("\105\099\111\110\073\109\097\103\101\082\097\116\105\111",T,f)end function Icon.setLabelYScale(s,D,f)local T=tonumber(D)or.45 return s:set("\105\099\111\110\076\097\098\101\108\089\083\099\097\108\101",T,f)end function Icon.setBaseZIndex(s,D,f)local T=tonumber(D)or 1 return s:set("\098\097\115\101\090\073\110\100\101\120",T,f)end function Icon._updateBaseZIndex(f,D)local s=f.instances.iconContainer local T=tonumber(D)or s.ZIndex local l=T-s.ZIndex if l==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 D,f in pairs(f.instances)do f.ZIndex=f.ZIndex+l end return true end function Icon.setSize(T,D,f,s)local l=tonumber(D)or 32 local B=tonumber(f)or l return T:set("\105\099\111\110\083\105\122\101",UDim2.new(0,l,0,B),s)end function Icon._updateIconSize(s,D,f)local T=12 local l=8 local B={iconImage=s:get("\105\099\111\110\073\109\097\103\101",f)or"\095\078\073\076";iconText=s:get("\105\099\111\110\084\101\120\116",f)or"\095\078\073\076";iconSize=s:get("\105\099\111\110\083\105\122\101",f)or"\095\078\073\076";iconImageYScale=s:get("\105\099\111\110\073\109\097\103\101\089\083\099\097\108\101",f)or"\095\078\073\076";iconImageRatio=s:get("\105\099\111\110\073\109\097\103\101\082\097\116\105\111",f)or"\095\078\073\076";iconLabelYScale=s:get("\105\099\111\110\076\097\098\101\108\089\083\099\097\108\101",f)or"\095\078\073\076"}for D,f in pairs(B)do if f=="\095\078\073\076"then return end end local X=s.instances.iconContainer local e=s.instances.iconLabel local C=s.instances.iconImage local n=s.instances.noticeFrame local z=B.iconSize.X.Offset local d=B.iconSize.X.Scale local O=z+d*X.Parent.AbsoluteSize.X local y=O local M=d>0 and O or 9999 local k=B.iconSize.Y.Offset local r=B.iconSize.Y.Scale local S=k+r*X.Parent.AbsoluteSize.Y local U=S*B.iconLabelYScale local h=(textService:GetTextSize(B.iconText,U,e.Font,Vector2.new(10000,U))).X local x=(S*B.iconImageYScale)*B.iconImageRatio local Z=B.iconImage~=""local i=B.iconText~=""local E=.5 local v if Z and not i then E=.45 s:set("\105\099\111\110\073\109\097\103\101\086\105\115\105\098\108\101",true,f)s: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),f)s:set("\105\099\111\110\073\109\097\103\101\080\111\115\105\116\105\111\110",UDim2.new(.5,0,.5,0),f)s:set("\105\099\111\110\073\109\097\103\101\083\105\122\101",UDim2.new(B.iconImageYScale*B.iconImageRatio,0,B.iconImageYScale,0),f)s:set("\105\099\111\110\076\097\098\101\108\086\105\115\105\098\108\101",false,f)elseif not Z and i then v=h+T*2 s:set("\105\099\111\110\076\097\098\101\108\086\105\115\105\098\108\101",true,f)s: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),f)s:set("\105\099\111\110\076\097\098\101\108\080\111\115\105\116\105\111\110",UDim2.new(0,T,.5,0),f)s:set("\105\099\111\110\076\097\098\101\108\083\105\122\101",UDim2.new(1,-T*2,B.iconLabelYScale,0),f)s: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,f)s:set("\105\099\111\110\073\109\097\103\101\086\105\115\105\098\108\101",false,f)elseif Z and i then local D=(T+x)+l v=(D+h)+T s:set("\105\099\111\110\073\109\097\103\101\086\105\115\105\098\108\101",true,f)s: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),f)s:set("\105\099\111\110\073\109\097\103\101\080\111\115\105\116\105\111\110",UDim2.new(0,T,.5,0),f)s:set("\105\099\111\110\073\109\097\103\101\083\105\122\101",UDim2.new(0,x,B.iconImageYScale,0),f)s:set("\105\099\111\110\076\097\098\101\108\086\105\115\105\098\108\101",true,f)s: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),f)s:set("\105\099\111\110\076\097\098\101\108\080\111\115\105\116\105\111\110",UDim2.new(0,D,.5,0),f)s:set("\105\099\111\110\076\097\098\101\108\083\105\122\101",UDim2.new(1,-D-T,B.iconLabelYScale,0),f)s: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,f)end if v then if not s._updatingIconSize then s._updatingIconSize=true local D=d>0 and d or 0 local T=d>0 and 0 or math.clamp(v,y,M)s:set("\105\099\111\110\083\105\122\101",UDim2.new(D,T,B.iconSize.Y.Scale,B.iconSize.Y.Offset),f,"\095\105\103\110\111\114\101\080\114\101\118\105\111\117\115")s._updatingIconSize=false end end s:set("\105\099\111\110\076\097\098\101\108\084\101\120\116\083\105\122\101",U,f)s:set("\110\111\116\105\099\101\070\114\097\109\101\080\111\115\105\116\105\111\110",UDim2.new(E,0,0,-2),f)if s.captionText then local D=6 local f=.8 local T=.58 local l=s.instances.captionContainer local B=s.instances.captionLabel local X=S*f local e=X*T local C=s:get("\099\097\112\116\105\111\110\070\111\110\116")local n=(textService:GetTextSize(s.captionText,e,C,Vector2.new(10000,e))).X B.TextSize=e B.Size=UDim2.new(0,n,T,0)l.Size=UDim2.new(0,n+D*2,0,S*f)end s._updatingIconSize=false end

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

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

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

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

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

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

function Icon:setRight(toggleState)
	return self:set("alignment", "right", toggleState)
end

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

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

function Icon:setLabelYScale(YScale, toggleState)
	local newYScale = tonumber(YScale) or 0.45
	return self:set("iconLabelYScale", newYScale, toggleState)
end
	
function Icon:setBaseZIndex(ZIndex, toggleState)
	local newBaseZIndex = tonumber(ZIndex) or 1
	return self:set("baseZIndex", newBaseZIndex, toggleState)
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, toggleState)
	local newXOffset = tonumber(XOffset) or 32
	local newYOffset = tonumber(YOffset) or newXOffset
	return self:set("iconSize", UDim2.new(0, newXOffset, 0, newYOffset), toggleState)
end

function Icon:_updateIconSize(_, toggleState)
	-- 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", toggleState) or "_NIL",
		iconText = self:get("iconText", toggleState) or "_NIL",
		iconSize = self:get("iconSize", toggleState) or "_NIL",
		iconImageYScale = self:get("iconImageYScale", toggleState) or "_NIL",
		iconImageRatio = self:get("iconImageRatio", toggleState) or "_NIL",
		iconLabelYScale = self:get("iconLabelYScale", toggleState) or "_NIL",
	}
	for k,v in pairs(values) do
		if v == "_NIL" then
			return
		end
	end

	local iconContainer = self.instances.iconContainer
	local iconLabel = self.instances.iconLabel
	local iconImage = self.instances.iconImage
	local noticeFrame = self.instances.noticeFrame

	-- 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 = 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, iconLabel.Font, 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
	
	if usingImage and not usingText then
		notifPosYScale = 0.45
		self:set("iconImageVisible", true, toggleState)
		self:set("iconImageAnchorPoint", Vector2.new(0.5, 0.5), toggleState)
		self:set("iconImagePosition", UDim2.new(0.5, 0, 0.5, 0), toggleState)
		self:set("iconImageSize", UDim2.new(values.iconImageYScale*values.iconImageRatio, 0, values.iconImageYScale, 0), toggleState)
		self:set("iconLabelVisible", false, toggleState)

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

	elseif usingImage and usingText then
		local labelGap = X_MARGIN + imageWidth + X_GAP
		desiredCellWidth = labelGap + labelWidth + X_MARGIN
		self:set("iconImageVisible", true, toggleState)
		self:set("iconImageAnchorPoint", Vector2.new(0, 0.5), toggleState)
		self:set("iconImagePosition", UDim2.new(0, X_MARGIN, 0.5, 0), toggleState)
		self:set("iconImageSize", UDim2.new(0, imageWidth, values.iconImageYScale, 0), toggleState)
		----
		self:set("iconLabelVisible", true, toggleState)
		self:set("iconLabelAnchorPoint", Vector2.new(0, 0.5), toggleState)
		self:set("iconLabelPosition", UDim2.new(0, labelGap, 0.5, 0), toggleState)
		self:set("iconLabelSize", UDim2.new(1, -labelGap-X_MARGIN, values.iconLabelYScale, 0), toggleState)
		self:set("iconLabelTextXAlignment", Enum.TextXAlignment.Left, toggleState)
	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), toggleState, "_ignorePrevious")
			self._updatingIconSize = false
		end
	end
	self:set("iconLabelTextSize", labelHeight, toggleState)
	self:set("noticeFramePosition", UDim2.new(notifPosYScale, 0, 0, -2), toggleState)

	-- Caption
	if self.captionText then
		local CAPTION_X_MARGIN = 6
		local CAPTION_CONTAINER_Y_SIZE_SCALE = 0.8
		local CAPTION_LABEL_Y_SCALE = 0.58
		local captionContainer = self.instances.captionContainer
		local captionLabel = self.instances.captionLabel
		local captionContainerHeight = cellHeight * CAPTION_CONTAINER_Y_SIZE_SCALE
		local captionLabelHeight = captionContainerHeight * CAPTION_LABEL_Y_SCALE
		local labelFont = self:get("captionFont")
		local textWidth = textService:GetTextSize(self.captionText, captionLabelHeight, labelFont, Vector2.new(10000, captionLabelHeight)).X
		captionLabel.TextSize = captionLabelHeight
		captionLabel.Size = UDim2.new(0, textWidth, CAPTION_LABEL_Y_SCALE, 0)
		captionContainer.Size = UDim2.new(0, textWidth + CAPTION_X_MARGIN*2, 0, cellHeight*CAPTION_CONTAINER_Y_SIZE_SCALE)
	end

	self._updatingIconSize = false
end


