local z=(script:FindFirstAncestor("\067\109\100\114\065\100\100\105\116\105\111\110\115")).Packages local A=require(z.Roact)local Y=2 local m={[16]="\114\098\120\097\115\115\101\116\105\100\058\047\047\051\048\053\054\053\052\049\049\055\055",[32]="\114\098\120\097\115\115\101\116\105\100\058\047\047\051\048\056\056\055\049\051\051\052\049",[64]="\114\098\120\097\115\115\101\116\105\100\058\047\047\052\057\049\056\054\055\055\049\050\052",[128]="\114\098\120\097\115\115\101\116\105\100\058\047\047\050\054\048\048\056\052\053\055\051\052";[500]="\114\098\120\097\115\115\101\116\105\100\058\047\047\050\054\048\057\049\051\056\053\050\051"}local W={Top={Center=Vector2.new(.5,.5),Size=Vector2.new(1,.5);Offset=Vector2.new(0,0)};Bottom={Center=Vector2.new(.5,0),Size=Vector2.new(1,.5),Offset=Vector2.new(0,.5)},Left={Center=Vector2.new(.5,.5);Size=Vector2.new(.5,1);Offset=Vector2.new(0,0)},Right={Center=Vector2.new(0,.5),Size=Vector2.new(.5,1),Offset=Vector2.new(.5,0)}}local a={TopLeft={Center=Vector2.new(.5,.5),Offset=Vector2.new(0,.5)};TopRight={Center=Vector2.new(0,.5),Offset=Vector2.new(.5,0)},BottomLeft={Center=Vector2.new(.5,0);Offset=Vector2.new(0,.5)},BottomRight={Center=Vector2.new(0,0),Offset=Vector2.new(.5,.5)}}local function H(z)local A=z/Y for z,Y in pairs(m)do if z>A then return z,Y end end error(("\067\111\117\108\100\110\'\116 \102\105\110\100 \099\105\114\099\108\101 \105\109\097\103\101 \102\111\114 \114\097\100\105\117\115 \037\100"):format(z))end local X=A.PureComponent:extend("\082\111\117\110\100\101\100\082\101\099\116\097\110\103\108\101")X.defaultProps={Mode="\065\108\108\067\111\114\110\101\114\115"}function X.render(z)local Y=z.props.Radius local m=z.props.Mode local X,F=H(Y)local h=X/2 local P,O,r if m=="\065\108\108\067\111\114\110\101\114\115"then P=Rect.new(h,h,h,h)else local A if m=="\083\105\110\103\108\101\069\100\103\101"then A=W[z.props.Edge]elseif m=="\083\105\110\103\108\101\067\111\114\110\101\114"then A=a[z.props.Corner]end if A.Center then local z=A.Center*X P=Rect.new(z,z)end if A.Size then O=A.Size*X end if A.Offset then r=A.Offset*X end end return A.createElement(z.props.Activated and"\073\109\097\103\101\066\117\116\116\111\110"or"\073\109\097\103\101\076\097\098\101\108",{Image=F;ImageColor3=z.props.Color,ImageTransparency=z.props.Transparency;ImageRectSize=O;ImageRectOffset=r;ScaleType=Enum.ScaleType.Slice;SliceCenter=P,SliceScale=(Y/X)*2,Size=z.props.Size,Position=z.props.Position,AnchorPoint=z.props.AnchorPoint,Rotation=z.props.Rotation;Active=z.props.Active;ClipsDescendants=z.props.ClipsDescendants,LayoutOrder=z.props.LayoutOrder,ZIndex=z.props.ZIndex,BackgroundTransparency=1;AutoButtonColor=z.props.Activated and false or nil;[A.Event.Activated]=z.props.Activated},z.props[A.Children])end return X
-- UICorner is still inconsistent as hell

local Packages = script:FindFirstAncestor("CmdrAdditions").Packages

local Roact = require(Packages.Roact)

local TARGET_SCALE = 2
local CIRCLE_IMAGES = {
	[16] = "rbxassetid://3056541177",
	[32] = "rbxassetid://3088713341",
	[64] = "rbxassetid://4918677124",
	[128] = "rbxassetid://2600845734",
	[500] = "rbxassetid://2609138523"
}

local SINGLE_EDGE_PROPS = {
	Top = { Center = Vector2.new(0.5, 0.5), Size = Vector2.new(1, 0.5), Offset = Vector2.new(0, 0) },
	Bottom = { Center = Vector2.new(0.5, 0), Size = Vector2.new(1, 0.5), Offset = Vector2.new(0, 0.5) },
	Left = { Center = Vector2.new(0.5, 0.5), Size = Vector2.new(0.5, 1), Offset = Vector2.new(0, 0) },
	Right = { Center = Vector2.new(0, 0.5), Size = Vector2.new(0.5, 1), Offset = Vector2.new(0.5, 0) }
}

local SINGLE_CORNER_PROPS = {
	TopLeft = { Center = Vector2.new(0.5, 0.5), Offset = Vector2.new(0, 0.5) },
	TopRight = { Center = Vector2.new(0, 0.5), Offset = Vector2.new(0.5, 0) },
	BottomLeft = { Center = Vector2.new(0.5, 0), Offset = Vector2.new(0, 0.5) },
	BottomRight = { Center = Vector2.new(0, 0), Offset = Vector2.new(0.5, 0.5) }
}

local function GetTargetSize(radius)
	local scaledRadius = radius / TARGET_SCALE

	for size, image in pairs(CIRCLE_IMAGES) do
		if size > scaledRadius then
			return size, image
		end
	end

	error(("Couldn't find circle image for radius %d"):format(radius))
end

local RoundedRectangle = Roact.PureComponent:extend("RoundedRectangle")

RoundedRectangle.defaultProps = {
	Mode = "AllCorners"
}

function RoundedRectangle:render()
	local radius = self.props.Radius
	local mode = self.props.Mode

	local targetSize, image = GetTargetSize(radius)
	local halfTargetSize = targetSize / 2

	local sliceCenter, imageRectSize, imageRectOffset

	if mode == "AllCorners" then
		sliceCenter = Rect.new(halfTargetSize, halfTargetSize, halfTargetSize, halfTargetSize)
	else
		local props
		if mode == "SingleEdge" then
			props = SINGLE_EDGE_PROPS[self.props.Edge]
		elseif mode == "SingleCorner" then
			props = SINGLE_CORNER_PROPS[self.props.Corner]
		end

		if props.Center then
			local center = props.Center * targetSize
			sliceCenter = Rect.new(center, center)
		end
		if props.Size then
			imageRectSize = props.Size * targetSize
		end
		if props.Offset then
			imageRectOffset = props.Offset * targetSize
		end
	end

	return Roact.createElement(self.props.Activated and "ImageButton" or "ImageLabel", {
		Image = image,
		ImageColor3 = self.props.Color,
		ImageTransparency = self.props.Transparency,
		ImageRectSize = imageRectSize,
		ImageRectOffset = imageRectOffset,

		ScaleType = Enum.ScaleType.Slice,
		SliceCenter = sliceCenter,
		SliceScale = radius / targetSize * 2,

		Size = self.props.Size,
		Position = self.props.Position,
		AnchorPoint = self.props.AnchorPoint,
		Rotation = self.props.Rotation,

		Active = self.props.Active,
		ClipsDescendants = self.props.ClipsDescendants,
		LayoutOrder = self.props.LayoutOrder,
		ZIndex = self.props.ZIndex,
		BackgroundTransparency = 1,

		AutoButtonColor = self.props.Activated and false or nil,
		[Roact.Event.Activated] = self.props.Activated
	}, self.props[Roact.Children])
end

return RoundedRectangle