local C={MOUNT="\109\111\117\110\116";UPDATE="\117\112\100\097\116\101",UNMOUNT="\117\110\109\111\117\110\116"}return function(c,n)local S=c.Component:extend("\084\114\101\101")function S.render(C)local n,U,O,w,p=C.props.breadth,C.props.components,C.props.depth,C.props.id,C.props.wrap local l=U.Box local R if O%2==0 then R="\099\111\108\117\109\110"else R="\114\111\119"end local N if O==0 then local C=c.createElement(l,{name="\105\100 \061 "..(w..("\044 \100\101\112\116\104 \061 "..(O.."\044 \035\099\104\105\108\100\114\101\110 \061 \048"))),color=w%3+3;automaticSize=false;usePadding=false})N={C}else N={}for C=1,n,1 do local w=c.createElement(S,{breadth=n;components=U;depth=O-1,wrap=p;id=C-1})table.insert(N,w)end end local L=c.createElement(l,{name="\105\100 \061 "..(w..("\044 \100\101\112\116\104 \061 "..(O..("\044 \035\099\104\105\108\100\114\101\110 \061 "..#N)))),color=w%3,automaticSize=true,usePadding=true;layout=R},N)for C=1,p,1 do L=c.createElement(l,{name="\119\114\097\112 \061 "..C,automaticSize=true,usePadding=false;color=-1},{L})end return L end return{Tree=S,displayName="\084\114\101\101",benchmarkType=C.MOUNT}end
-- TODO: Move to benchmark init.
local BenchmarkType = {
	MOUNT = "mount",
	UPDATE = "update",
	UNMOUNT = "unmount",
}

return function(Roact, ReactRoblox)
	local Tree = Roact.Component:extend("Tree")

	function Tree:render()
		local breadth, components, depth, id, wrap =
			self.props.breadth, self.props.components, self.props.depth, self.props.id, self.props.wrap
		local Box = components.Box

		-- ROBLOX deviation: ternary isn't supported.
		local layout
		if depth % 2 == 0 then
			layout = "column"
		else
			layout = "row"
		end

		local children
		if depth == 0 then
			local fixedBox = Roact.createElement(Box, {
				name = "id = " .. id .. ", depth = " .. depth .. ", #children = 0",
				color = (id % 3) + 3,
				automaticSize = false,
				usePadding = false,
			})
			children = { fixedBox }
		else
			-- ROBLOX deviation: can't use Array.from() as upstream relies on
			-- duck typing of "length" property to expand an object into an
			-- array the size of "length". Lua doesn't use the "length" property
			-- for obtaining array length so this can't be mimicked.

			children = {}
			for i = 1, breadth do
				local tree = Roact.createElement(Tree, {
					breadth = breadth,
					components = components,
					depth = depth - 1,
					wrap = wrap,
					id = i - 1,
				})
				table.insert(children, tree)
			end
		end

		local result = Roact.createElement(Box, {
			name = "id = " .. id .. ", depth = " .. depth .. ", #children = " .. #children,
			color = id % 3,
			automaticSize = true,
			usePadding = true,
			layout = layout,
		}, children)

		for i = 1, wrap do
			result = Roact.createElement(Box, {
				name = "wrap = " .. i,
				automaticSize = true,
				usePadding = false,
				color = -1,
			}, {
				result,
			})
		end

		return result
	end

	-- ROBLOX deviation: we use function components and move static props to
	-- exports so they're accessible.
	return {
		Tree = Tree,
		displayName = "Tree",
		benchmarkType = BenchmarkType.MOUNT,
	}
end
