local n=require((script:FindFirstAncestor("\077\097\122\101\071\101\110\101\114\097\116\111\114\080\108\117\103\105\110")).Roact)local Z=require(script.Parent.Parent.Dictionary)local w=n.createElement local i=n.Component:extend("\070\105\116\076\105\115\116")function i.init(Z)Z.sizeBinding,Z.setSize=n.createBinding(UDim2.new())end function i.render(i)local X=i.props.containerKind or"\070\114\097\109\101"local G=i.props.fitAxes or"\088\089"local K=i.props.containerProps local V=i.props.layoutProps local F=i.props.paddingProps local y if F~=nil then y=w("\085\073\080\097\100\100\105\110\103",F)end local J=Z.merge(i.props[n.Children],{["\036\076\097\121\111\117\116"]=w("\085\073\076\105\115\116\076\097\121\111\117\116",Z.merge({SortOrder=Enum.SortOrder.LayoutOrder;[n.Change.AbsoluteContentSize]=function(n)local Z=n.AbsoluteContentSize if F~=nil then Z=Z+Vector2.new(F.PaddingLeft.Offset+F.PaddingRight.Offset,F.PaddingTop.Offset+F.PaddingBottom.Offset)end local w if G=="\088"then w=UDim2.new(0,Z.X,K.Size.Y.Scale,K.Size.Y.Offset)elseif G=="\089"then w=UDim2.new(K.Size.X.Scale,K.Size.X.Offset,0,Z.Y)elseif G=="\088\089"then w=UDim2.new(0,Z.X,0,Z.Y)else error("\073\110\118\097\108\105\100 \102\105\116\065\120\101\115 \118\097\108\117\101")end i.setSize(w)end},V));["\036\080\097\100\100\105\110\103"]=y})local v=Z.merge(K,{Size=i.sizeBinding})return w(X,v,J)end return i
local Roact = require(script:FindFirstAncestor('MazeGeneratorPlugin').Roact)

local Dictionary = require(script.Parent.Parent.Dictionary)

local e = Roact.createElement

local FitList = Roact.Component:extend('FitList')

function FitList:init()
	self.sizeBinding, self.setSize = Roact.createBinding(UDim2.new())
end

function FitList:render()
	local containerKind = self.props.containerKind or 'Frame'
	local fitAxes = self.props.fitAxes or 'XY'
	local containerProps = self.props.containerProps
	local layoutProps = self.props.layoutProps
	local paddingProps = self.props.paddingProps

	local padding
	if paddingProps ~= nil then
		padding = e('UIPadding', paddingProps)
	end

	local children = Dictionary.merge(self.props[Roact.Children], {
		['$Layout'] = e(
			'UIListLayout',
			Dictionary.merge(
				{
					SortOrder = Enum.SortOrder.LayoutOrder,
					[Roact.Change.AbsoluteContentSize] = function(instance)
						local contentSize = instance.AbsoluteContentSize

						if paddingProps ~= nil then
							contentSize =
								contentSize + Vector2.new(
									paddingProps.PaddingLeft.Offset + paddingProps.PaddingRight.Offset,
									paddingProps.PaddingTop.Offset + paddingProps.PaddingBottom.Offset
								)
						end

						local combinedSize

						if fitAxes == 'X' then
							combinedSize =
								UDim2.new(
									0,
									contentSize.X,
									containerProps.Size.Y.Scale,
									containerProps.Size.Y.Offset
								)
						elseif fitAxes == 'Y' then
							combinedSize =
								UDim2.new(
									containerProps.Size.X.Scale,
									containerProps.Size.X.Offset,
									0,
									contentSize.Y
								)
						elseif fitAxes == 'XY' then
							combinedSize = UDim2.new(0, contentSize.X, 0, contentSize.Y)
						else
							error('Invalid fitAxes value')
						end

						self.setSize(combinedSize)
					end,
				},
				layoutProps
			)
		),
		['$Padding'] = padding,
	})

	local fullContainerProps = Dictionary.merge(containerProps, { Size = self.sizeBinding })

	return e(containerKind, fullContainerProps, children)
end

return FitList