local p=require(script.Parent.Parent.Configuration)local m=require(script.Parent.RadioButton)local O=require(script.Parent.TextView)local j=p.Roact local q=j.Component:extend("\077\097\116\101\114\105\097\108\082\097\100\105\111\071\114\111\117\112")function q.init(m,p)m:setState({CurrentId=p.CurrentId})end function q.render(p)local q={Layout=j.createElement("\085\073\076\105\115\116\076\097\121\111\117\116",{Padding=UDim.new(0,8),SortOrder="\078\097\109\101"})}for f,Y in next,p.props.Options do local S=j.createElement("\084\101\120\116\066\117\116\116\111\110",{BackgroundTransparency=1,Text="";Size=UDim2.new(1,0,0,24),[j.Event.MouseButton1Click]=function()if p.props.CurrentIdChanged then p.props.CurrentIdChanged(f)end p:setState({CurrentId=f})end},{RadioButton=j.createElement(m,{Checked=f==p.state.CurrentId;OnClicked=function()if p.props.CurrentIdChanged then p.props.CurrentIdChanged(f)end p:setState({CurrentId=f})end}),TextLabel=j.createElement(O,{Class="\066\111\100\121\049";Position=UDim2.fromOffset(30,0);Size=UDim2.new(1,-30,0,24),Text=Y;TextXAlignment=Enum.TextXAlignment.Left})})q["\082\097\100\105\111\066\117\116\116\111\110\095\095"..tostring(f)]=S end local f=p.props.Size if p.props.SizeFromContents then local m=0 for p,j in next,p.props.Options do local q=O.getTextBounds(tostring(j),"\066\111\100\121\049")if q.X>m then m=q.X end end f=UDim2.fromOffset((30+m)+8,32)end return j.createElement("\070\114\097\109\101",{BackgroundTransparency=1,Size=f,Position=p.props.Position},q)end return q
local Configuration = require(script.Parent.Parent.Configuration)
local RadioButton = require(script.Parent.RadioButton)
local TextView = require(script.Parent.TextView)

local Roact = Configuration.Roact

local RadioGroup = Roact.Component:extend("MaterialRadioGroup")

function RadioGroup:init(props)
	self:setState({
		CurrentId = props.CurrentId,
	})
end

function RadioGroup:render()
	local children = {
		Layout = Roact.createElement("UIListLayout", {
			Padding = UDim.new(0, 8),
			SortOrder = "Name",
		}),
	}

	for id, label in next, self.props.Options do
		local element = Roact.createElement("TextButton", {
			BackgroundTransparency = 1,
			Text = "",
			Size = UDim2.new(1, 0, 0, 24),

			[Roact.Event.MouseButton1Click] = function()
				if self.props.CurrentIdChanged then
					self.props.CurrentIdChanged(id)
				end

				self:setState({
					CurrentId = id,
				})
			end,
		}, {
			RadioButton = Roact.createElement(RadioButton, {
				Checked = id == self.state.CurrentId,
				OnClicked = function()
					if self.props.CurrentIdChanged then
						self.props.CurrentIdChanged(id)
					end

					self:setState({
						CurrentId = id,
					})
				end
			}),

			TextLabel = Roact.createElement(TextView, {
				Class = "Body1",
				Position = UDim2.fromOffset(30, 0),
				Size = UDim2.new(1, -30, 0, 24),
				Text = label,
				TextXAlignment = Enum.TextXAlignment.Left,
			}),
		})

		children["RadioButton__" .. tostring(id)] = element
	end

	local size = self.props.Size

	if self.props.SizeFromContents then
		local maximumTextWidth = 0
		for _, label in next, self.props.Options do
			local bounds = TextView.getTextBounds(tostring(label), "Body1")

			if bounds.X > maximumTextWidth then
				maximumTextWidth = bounds.X
			end
		end

		size = UDim2.fromOffset(30 + maximumTextWidth + 8, 32)
	end

	return Roact.createElement("Frame", {
		BackgroundTransparency = 1,
		Size = size,
		Position = self.props.Position,
	}, children)
end

return RadioGroup
