local T=script.Parent.Parent local O=require(T.Constants)local a=require(T.Packages.Roact)local D=require(T.Packages.StudioComponents)local w=D.Widget local v=D.Label local H=D.TextInput local t=D.Button local A=D.MainButton local c=game:GetService("\080\104\121\115\105\099\115\083\101\114\118\105\099\101")local I=a.Component:extend("\071\114\111\117\112\078\097\109\101\087\105\100\103\101\116")function I.init(T)T:setState({LastText=""})end function I.render(T)local D=T.state.LastText local I=c:GetRegisteredCollisionGroups()local Q=true local q=nil if#D==0 then Q=false elseif string.find(D,"\091\092\037\094\093")then Q=false q="\067\097\110\110\111\116 \104\097\118\101 \092 \111\114 \094"else for T,O in ipairs(I)do if O.name==D then Q=false q="\078\097\109\101 \097\108\114\101\097\100\121 \117\115\101\100"break end end end return a.createElement(w,{Id=O.ModalWidgetId;Name=O.ModalWidgetId;Title=T.props.Title;InitialDockState=Enum.InitialDockState.Float;MinimumWindowSize=Vector2.new(185,85);OnClosed=T.props.OnClosed},{Padding=a.createElement("\085\073\080\097\100\100\105\110\103",{PaddingLeft=UDim.new(0,7);PaddingRight=UDim.new(0,7);PaddingTop=UDim.new(0,7),PaddingBottom=UDim.new(0,4)}),Label=a.createElement(v,{Size=UDim2.fromOffset(31,20);Text="\078\097\109\101",TextXAlignment=Enum.TextXAlignment.Left,TextTruncate=Enum.TextTruncate.AtEnd});InputHolder=a.createElement("\070\114\097\109\101",{Position=UDim2.fromOffset(38,0),Size=UDim2.new(1,-38,0,20);BackgroundTransparency=1},{Input=a.createElement(H,{ClearTextOnFocus=false,PlaceholderText="\069\110\116\101\114 \110\097\109\101";Text=T.state.LastText;OnChanged=function(O)T:setState({LastText=O})end;OnFocusLost=function(O,a)if a and Q then T.props.OnSubmitted(D)end end})}),Message=q and a.createElement(v,{Position=UDim2.fromOffset(38,21);Size=UDim2.new(1,-38,0,20),Text=q;TextXAlignment=Enum.TextXAlignment.Left;TextTruncate=Enum.TextTruncate.AtEnd;TextColorStyle=Enum.StudioStyleGuideColor.ErrorText});Buttons=a.createElement("\070\114\097\109\101",{AnchorPoint=Vector2.new(0,1),Position=UDim2.fromScale(0,1);Size=UDim2.new(1,0,0,28),BackgroundTransparency=1},{Layout=a.createElement("\085\073\076\105\115\116\076\097\121\111\117\116",{SortOrder=Enum.SortOrder.LayoutOrder;FillDirection=Enum.FillDirection.Horizontal,HorizontalAlignment=Enum.HorizontalAlignment.Right,Padding=UDim.new(0,4)});CreateButton=a.createElement(A,{LayoutOrder=2,Size=UDim2.new(0,65,1,0),Text=T.props.Action,Disabled=not Q;OnActivated=function()T.props.OnSubmitted(D)end});CancelButton=a.createElement(t,{LayoutOrder=1,Size=UDim2.new(0,65,1,0),Text="\067\097\110\099\101\108";OnActivated=T.props.OnClosed})})})end return I
local Plugin = script.Parent.Parent
local Constants = require(Plugin.Constants)

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

local Widget = StudioComponents.Widget
local Label = StudioComponents.Label
local TextInput = StudioComponents.TextInput
local Button = StudioComponents.Button
local MainButton = StudioComponents.MainButton

local PhysicsService = game:GetService("PhysicsService")
local GroupNameWidget = Roact.Component:extend("GroupNameWidget")

function GroupNameWidget:init()
	self:setState({ LastText = "" })
end

function GroupNameWidget:render()
	local lastText = self.state.LastText
	local groups = PhysicsService:GetRegisteredCollisionGroups()

	local valid = true
	local message = nil
	if #lastText == 0 then
		valid = false
	elseif string.find(lastText, "[\\%^]") then
		valid = false
		message = "Cannot have \\ or ^"
	else
		for _, group in ipairs(groups) do
			if group.name == lastText then
				valid = false
				message = "Name already used"
				break
			end
		end
	end

	return Roact.createElement(Widget, {
		Id = Constants.ModalWidgetId,
		Name = Constants.ModalWidgetId,
		Title = self.props.Title,
		InitialDockState = Enum.InitialDockState.Float,
		MinimumWindowSize = Vector2.new(185, 85),
		OnClosed = self.props.OnClosed,
	}, {
		Padding = Roact.createElement("UIPadding", {
			PaddingLeft = UDim.new(0, 7),
			PaddingRight = UDim.new(0, 7),
			PaddingTop = UDim.new(0, 7),
			PaddingBottom = UDim.new(0, 4),
		}),
		Label = Roact.createElement(Label, {
			Size = UDim2.fromOffset(31, 20),
			Text = "Name",
			TextXAlignment = Enum.TextXAlignment.Left,
			TextTruncate = Enum.TextTruncate.AtEnd,
		}),
		InputHolder = Roact.createElement("Frame", {
			Position = UDim2.fromOffset(38, 0),
			Size = UDim2.new(1, -38, 0, 20),
			BackgroundTransparency = 1,
		}, {
			Input = Roact.createElement(TextInput, {
				ClearTextOnFocus = false,
				PlaceholderText = "Enter name",
				Text = self.state.LastText,
				OnChanged = function(text)
					self:setState({ LastText = text })
				end,
				OnFocusLost = function(_, enterPressed)
					if enterPressed and valid then
						self.props.OnSubmitted(lastText)
					end
				end,
			}),
		}),
		Message = message and Roact.createElement(Label, {
			Position = UDim2.fromOffset(38, 21),
			Size = UDim2.new(1, -38, 0, 20),
			Text = message,
			TextXAlignment = Enum.TextXAlignment.Left,
			TextTruncate = Enum.TextTruncate.AtEnd,
			TextColorStyle = Enum.StudioStyleGuideColor.ErrorText,
		}),
		Buttons = Roact.createElement("Frame", {
			AnchorPoint = Vector2.new(0, 1),
			Position = UDim2.fromScale(0, 1),
			Size = UDim2.new(1, 0, 0, 28),
			BackgroundTransparency = 1,
		}, {
			Layout = Roact.createElement("UIListLayout", {
				SortOrder = Enum.SortOrder.LayoutOrder,
				FillDirection = Enum.FillDirection.Horizontal,
				HorizontalAlignment = Enum.HorizontalAlignment.Right,
				Padding = UDim.new(0, 4),
			}),
			CreateButton = Roact.createElement(MainButton, {
				LayoutOrder = 2,
				Size = UDim2.new(0, 65, 1, 0),
				Text = self.props.Action,
				Disabled = not valid,
				OnActivated = function()
					self.props.OnSubmitted(lastText)
				end,
			}),
			CancelButton = Roact.createElement(Button, {
				LayoutOrder = 1,
				Size = UDim2.new(0, 65, 1, 0),
				Text = "Cancel",
				OnActivated = self.props.OnClosed,
			}),
		}),
	})
end

return GroupNameWidget
