local A=script.Parent.Parent local m=require(A:WaitForChild("\076\097\122\121\076\111\097\100\101\114"))local Y={}Y.__index=Y Y.__type="\082\097\100\105\111\066\117\116\116\111\110\076\097\098\101\108"function Y.__tostring(A)return Y.__type end function Y.new(A,x)local a=setmetatable({},Y)a._Maid=m.Utilities.Maid.new()a._ChangedBind=Instance.new("\066\105\110\100\097\098\108\101\069\118\101\110\116")a._ActiveRadio=x[1]a.Frame=A a.RadioButtons=x a.Changed=a._ChangedBind.Event init(a)return a end function Y.Create(A,x)local a={}local function s(A,Y)local x=m.Classes.RadioButtonLabel.Create(Y)x.Frame.LayoutOrder=A a[A]=x return x.Frame end local t=m.Constructors.List.Create(A,x or#A,Enum.FillDirection.Vertical,UDim.new(0,5),s)return Y.new(t,a)end function init(A)for m,Y in next,A.RadioButtons do Y:SetValue(false)A._Maid:Mark(Y.Button.Activated:Connect(function()local m=A._ActiveRadio A._ActiveRadio:SetValue(false)A._ActiveRadio=Y A._ActiveRadio:SetValue(true)A._ChangedBind:Fire(m,Y)end))end A._ActiveRadio:SetValue(true)end function Y.GetActiveRadio(A)return A._ActiveRadio end function Y.Destroy(A)A._Maid:Sweep()A.Frame:Destroy()end return Y
--[[
Classes.RadioButtonGroup

This class creates a list of radio buttons that the user can select from.

Constructors:
	new(frame [instance], buttons[] [RadioButtonLabel])
	Create(list[] [string], max [integer])
		> Creates a RadioButtonGroup from the list with a max scrolling number.

Properties:
	Frame [instance]
		> The container frame for the RadioButtonGroup. Can be used for positioning and resizing.
	RadioButtons[] [RadioButtonLabel]
 		> An array of the RadioButtonLabels that are used in the RadioButtonGroup.

Methods:
	:GetActiveRadio() [RadioButtonLabel]
		> Returns the currently selected RadioButtonLabel
	:Destroy() [void]
		> Destroys the RadioButtonGroup and all the events, etc that were running it.

Events:
	.Changed:Connect(function(old [RadioButtonLabel], new [RadioButtonLabel])
		> When the selected radio button is changed in the radio button group this event fires
--]]

-- CONSTANTS

local GuiLib = script.Parent.Parent
local Lazy = require(GuiLib:WaitForChild("LazyLoader"))

-- Class

local RadioButtonGroupClass = {}
RadioButtonGroupClass.__index = RadioButtonGroupClass
RadioButtonGroupClass.__type = "RadioButtonLabel"

function RadioButtonGroupClass:__tostring()
	return RadioButtonGroupClass.__type
end

-- Public Constructors

function RadioButtonGroupClass.new(frame, radioButtons)
	local self = setmetatable({}, RadioButtonGroupClass)
	
	self._Maid = Lazy.Utilities.Maid.new()
	self._ChangedBind = Instance.new("BindableEvent")
	self._ActiveRadio = radioButtons[1]
	
	self.Frame = frame
	self.RadioButtons = radioButtons
	self.Changed = self._ChangedBind.Event
	
	init(self)
	
	return self
end

function RadioButtonGroupClass.Create(list, max)
	local radios = {}
	
	local function instanceFunc(index, option)
		local radio = Lazy.Classes.RadioButtonLabel.Create(option)
		radio.Frame.LayoutOrder = index
		radios[index] = radio
		return radio.Frame
	end
	
	local frame = Lazy.Constructors.List.Create(list, max or #list, Enum.FillDirection.Vertical, UDim.new(0, 5), instanceFunc)
	
	return RadioButtonGroupClass.new(frame, radios)
end

-- Private Methods

function init(self)
	for _, radio in next, self.RadioButtons do
		radio:SetValue(false)
		self._Maid:Mark(radio.Button.Activated:Connect(function()
			local old = self._ActiveRadio
			
			self._ActiveRadio:SetValue(false)
			self._ActiveRadio = radio
			self._ActiveRadio:SetValue(true)
			
			self._ChangedBind:Fire(old, radio)
		end))
	end
	
	self._ActiveRadio:SetValue(true)
end

-- Public Methods

function RadioButtonGroupClass:GetActiveRadio()
	return self._ActiveRadio
end

function RadioButtonGroupClass:Destroy()
	self._Maid:Sweep()
	self.Frame:Destroy()
end

--

return RadioButtonGroupClass