local T=game:GetService("\083\101\108\101\099\116\105\111\110")local O=script.Parent.Parent local a=require(O.Packages.Roact)local D=require(O.Packages.StudioComponents)local w=D.Button local v=a.Component:extend("\065\100\100\084\111\071\114\111\117\112")function v.init(O)O:setState({Selection=T:Get()})O.onActivated=function()local T={}local a=O.props.SelectedGroupName for O,D in ipairs(O.state.Selection)do if D:IsA("\066\097\115\101\080\097\114\116")and D.CollisionGroup~=a then table.insert(T,D)end end O.props.BatchSetCollisionGroup(T,a)end end function v.didMount(O)O.selectionChanged=T.SelectionChanged:Connect(function()O:setState({Selection=T:Get()})end)end function v.willUnmount(T)T.selectionChanged:Disconnect()end function v.render(T)local O=false local D=T.props.SelectedGroupName for T,a in ipairs(T.state.Selection)do if not a:IsA("\066\097\115\101\080\097\114\116")then continue elseif a.CollisionGroup~=D then O=true break end end return a.createElement(w,{LayoutOrder=1;Size=UDim2.new(.38,-4,1,0);Text="\065\100\100 \116\111 \071\114\111\117\112";Disabled=T.props.Disabled or not O;OnActivated=T.onActivated})end return v
local SelectionService = game:GetService("Selection")

local Plugin = script.Parent.Parent

local Roact = require(Plugin.Packages.Roact)
local StudioComponents = require(Plugin.Packages.StudioComponents)

local Button = StudioComponents.Button

local AddToGroup = Roact.Component:extend("AddToGroup")

function AddToGroup:init()
	self:setState({ Selection = SelectionService:Get() })
	self.onActivated = function()
		local targets = {}
		local targetGroupName = self.props.SelectedGroupName
		for _, instance in ipairs(self.state.Selection) do
			if instance:IsA("BasePart") and instance.CollisionGroup ~= targetGroupName then
				table.insert(targets, instance)
			end
		end
		self.props.BatchSetCollisionGroup(targets, targetGroupName)
	end
end

function AddToGroup:didMount()
	self.selectionChanged = SelectionService.SelectionChanged:Connect(function()
		self:setState({ Selection = SelectionService:Get() })
	end)
end

function AddToGroup:willUnmount()
	self.selectionChanged:Disconnect()
end

function AddToGroup:render()
	local valid = false
	local targetGroupName = self.props.SelectedGroupName
	for _, instance in ipairs(self.state.Selection) do
		if not instance:IsA("BasePart") then
			continue
		elseif instance.CollisionGroup ~= targetGroupName then
			valid = true
			break
		end
	end
	return Roact.createElement(Button, {
		LayoutOrder = 1,
		Size = UDim2.new(0.38, -4, 1, 0),
		Text = "Add to Group",
		Disabled = self.props.Disabled or not valid,
		OnActivated = self.onActivated,
	})
end

return AddToGroup
